home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.os.linux.misc      Linux-specific topics not covered by oth      135,536 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 134,271 of 135,536   
   John Ames to John Levine   
   Re: C structures, was naughty Python   
   02 Jan 26 15:44:23   
   
   XPost: alt.folklore.computers   
   From: commodorejohn@gmail.com   
      
   On Fri, 2 Jan 2026 22:41:42 -0000 (UTC)   
   John Levine  wrote:   
      
   > >> ... it's not guaranteed that the compiler won't take liberties in   
   > >> arranging members of a struct for optimization purposes ...     
   > >   
   > >The C23 spec (section 6.2.5, “Types”) does say the member objects of   
   > >a struct type need to be “sequentially allocated”.     
   >    
   > That language has been there a long time.  It's in my copy of C11 and   
   > it wasn't new then.  It's probably always been there since we wrote   
   > code that used the common struct prefix hack in K&R C.   
      
   I went to check and, lo, it's in the C89 spec as well; as was already   
   indicated by Lawrence, I must've been thinking of compilers inserting   
   padding for alignment purposes. Which does raise the same basic concern   
   (the block of memory allocated to a struct is not *necessarily* a 1:1   
   concatenation of its members, and casting pointers between different   
   data structures should be done with caution,) but my recollection was   
   evidently in need of clarification.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca