home bbs files messages ]

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

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

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

   Message 243,029 of 243,242   
   Keith Thompson to David Brown   
   Re: UB or not UB? was: On Undefined Beha   
   15 Jan 26 04:04:05   
   
   From: Keith.S.Thompson+u@gmail.com   
      
   David Brown  writes:   
   > On 14/01/2026 23:43, Keith Thompson wrote:   
   [...]   
   >> There can be arbitrary padding between struct members, or after the   
   >> last member.  Almost(?) all implementations add padding only to   
   >> satisfy alignment requirements, but the standard doesn't state any   
   >> restrictions.  There can be no padding before the first member, and   
   >> offsets of members must be increasing.   
   >   
   > On closer reading, I agree with you here.  I find it a little   
   > surprising that this is not implementation-defined.  If an   
   > implementation can arbitrarily add extra padding within a struct, it   
   > severely limits the use of structs in contexts outside the current   
   > translation unit.   
      
   In practice, struct layouts are (I think) typically specified by   
   a system's ABI, and ABIs generally permit/require only whatever   
   padding is necessary to meet alignment requirements.   
      
   And I think C has rules about type compatibility that are intended to   
   cover the same struct definition being used in different translation   
   units within a program, though I'm too lazy to look up the details.   
      
   [...]   
      
   --   
   Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com   
   void Void(void) { Void(); } /* The recursive call of the void */   
      
   --- 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