[Bug c++/12615] [3.3 Regression] initializer syntax for POD structs gives parse error

bruno at clisp dot org gcc-bugzilla@gcc.gnu.org
Wed Oct 15 11:49:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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



------- Additional Comments From bruno at clisp dot org  2003-10-15 11:49 -------
Gabriel dos Reis writes: 
> | The problem with this is that it is not a syntax which is valid in 
> | initializers _and_  expressions. I'd need to write  
> 
> The C99 standard syntax works in both cases 
 
No it doesn't. None of the possible syntaxes work both in initializer position 
and in expression position, with g++ 3.3.1: 
 
===================================================== 
struct object 
{ 
  unsigned long one_o; 
  unsigned int allocstamp; 
}; 
typedef struct object object; 
void gc_mark (object obj) 
{ 
  // Old GNU designated initializer syntax, without cast. 
  { 
    // As initializer. 
    object a = { one_o: 0, allocstamp: 0 }; 
    // As expression - syntax error in gcc and g++. 
    object b; b = { one_o: 0, allocstamp: 0 }; 
  } 
  // Old GNU designated initializer syntax, with cast. 
  { 
    // As initializer - syntax error in g++. 
    object a = (object) { one_o: 0, allocstamp: 0 }; 
    // As expression. 
    object b; b = (object) { one_o: 0, allocstamp: 0 }; 
  } 
  // New ISO C 99 designated initializer syntax, without cast. 
  { 
    // As initializer - syntax error in g++. 
    object a = { .one_o = 0, .allocstamp = 0 }; 
    // As expression - syntax error in gcc and g++. 
    object b; b = { .one_o = 0, .allocstamp = 0 }; 
  } 
  // New ISO C 99 designated initializer syntax, with cast. 
  { 
    // As initializer - syntax error in g++. 
    object a = (object) { .one_o = 0, .allocstamp = 0 }; 
    // As expression - syntax error in g++. 
    object b; b = (object) { .one_o = 0, .allocstamp = 0 }; 
  } 
} 
========================================================= 
 
Which of the four syntaxes you recommend me to choose?



More information about the Gcc-bugs mailing list