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,030 of 243,242   
   David Brown to Keith Thompson   
   Re: UB or not UB? was: On Undefined Beha   
   15 Jan 26 13:56:09   
   
   From: david.brown@hesbynett.no   
      
   On 15/01/2026 13:04, Keith Thompson wrote:   
   > 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.   
      
   Sure.  I would be very surprised to see a real compiler add extra   
   padding in a struct, beyond what was needed for alignment.  And real   
   compilers usually use well-documented ABI's that go beyond the   
   requirements of C's implementation-defined behaviours in their detail.   
   It just strikes me as a little odd that the standard says   
   implementations must document things like how they split bit-fields   
   between addressable units, but makes no requirements at all about how   
   much extra padding they can have between struct fields.   
      
   >   
   > 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.   
   >   
   > [...]   
   >   
      
   --- 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