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 242,444 of 243,242   
   Tim Rentsch to Andrey Tarasevich   
   Re: GCC bug   
   14 Dec 25 22:38:34   
   
   From: tr.17687@z991.linuxsc.com   
      
   Andrey Tarasevich  writes:   
      
   > An attempt to use designated initializers to explicitly re-initialize   
   > a sub-member `y` of a struct member `b.a`   
   >   
   >   #include    
   >   
   >   struct A { int x, y; };   
   >   struct B { struct A a; };   
   >   
   >   int main(void)   
   >   {   
   >     struct A ia = { 1, 2 };   
   >     struct B b = { .a = ia, .a.y = 42 };   
   >     printf("%d %d\n", b.a.x, b.a.y);   
   >   }   
   >   
   > GCC outputs:   
   >   
   >   0 42   
   >   
   > I.e. it does initialize `b.a.y` with `42`, but for some reason also   
   > produces zero in `b.a.x`. Meanwhile, Clang, MSVC output   
   >   
   >   1 42   
   >   
   > as expected.   
   >   
   > The funny part is that this exact functionality is actually directly   
   > illustrated by the standard in "6.7.11 Initialization" example 12.   
   >   
   > Is it just a bug or is there some defiant reasoning (e.g. "we know   
   > better") for GCC's behavior?   
      
   Given the example that is shown in the C standard, it seems clear   
   that what gcc does is wrong, so may be called a bug.   
      
   --- 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