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 241,280 of 243,242   
   Kaz Kylheku to Keith Thompson   
   Re: Nice way of allocating flexible stru   
   10 Oct 25 04:20:41   
   
   From: 643-408-1753@kylheku.com   
      
   On 2025-10-10, Keith Thompson  wrote:   
   > Several implementations I've tried (gcc, clang, tcc) implement the   
   > offsetof macro via "__builtin_offsetof".  Whatever compiler magic   
   > is used to implement "__builtin_offsetof" typically works correctly   
   > for Kaz's example (which is of course one of the possible results of   
   > undefined behavior).   
      
   It is a documented extension, because GCC parses it, and the reason is   
   given in GCC's documented grammar for the feature:   
      
   primary:   
           "__builtin_offsetof" "(" typename "," offsetof_member_designator ")"   
      
   offsetof_member_designator:   
             identifier   
           | offsetof_member_designator "." identifier   
           | offsetof_member_designator "[" expr "]"   
      
   Accompanied by the remark: "In either case, member may consist of a   
   single identifier, or a sequence of member accesses and array   
   references."   
      
   This is a section under: https://gcc.gnu.org/onlinedocs/gcc/Synt   
   x-Extensions.html   
      
   Expr is not constrained to be constant.   
      
   It is not explained what the semantics is of the extended designator,   
   but it can be reasonably inferred.   
      
   There are probably code bases out there which perpetrate that trick;   
   GCC has been in many places and had lots of people hack on it.   
      
   --   
   TXR Programming Language: http://nongnu.org/txr   
   Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal   
   Mastodon: @Kazinator@mstdn.ca   
      
   --- 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