[Bug c/10676] Using unnamed fields in initializers

jan dot cornelis at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Aug 27 14:58:00 GMT 2009



------- Comment #11 from jan dot cornelis at gmail dot com  2009-08-27 14:57 -------
An example program that shows 3 different methods. Only one works (see comment) 
As I used the names for each field, I assumed that all 3 examples should work. 

#include <inttypes.h>
#include <stdio.h>

struct a_t {
  uint16_t a;
  uint16_t b;
  union {
      uint8_t c;
    uint16_t d;
  };
};

#if (1)
struct a_t alfa = {
  .a = 1,
  .b = 2,
  .c = 3, //Will not work
};
#elif (0)
struct a_t alfa = {
  .a = 1,
  .b = 2,
  {.c = 3}, //works
};
#elif (0)
struct a_t alfa = {
  .a = 1,
  {.c= 2}, //Does not work
  .b = 3,
}
#endif

int main(void)
{
  //alfa.c = 4;
  //alfa.d = 5;
  printf("%20s:%d\n","alfa.a",alfa.a);
  printf("%20s:%d\n","alfa.b",alfa.b);
  printf("%20s:%d\n","alfa.c",alfa.c);
  printf("%20s:%d\n","alfa.d",alfa.d);
 return 0; 
}


-- 

jan dot cornelis at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jan dot cornelis at gmail
                   |                            |dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10676



More information about the Gcc-bugs mailing list