I have an aggregate with this definition: typedef union vec3 { struct { double x, y, z; }; double component[3]; } vec3;
Given this definition, I tried to write the following: static inline vec3 vec_add(vec3 a, vec3 b) { return (vec3) { .x = a.x + b.x, .y = a.y + b.y, .z = a.z + b.z, }; } GCC complained about this: vec.h: In function vec_add: vec.h:15: error: missing braces around initializer vec.h:15: error: (near initialization for (anonymous).<anonymous>) If I had given the nameless inner struct a name, such as "foo", I could have written: static inline vec3 vec_add(vec3 a, vec3 b) { return (vec3) { .foo.x = a.foo.x + b.foo.x, .foo.y = a.foo.y + b.foo.y, .foo.z = a.foo.z + b.foo.z, }; } So since the inner struct does not have a name, it seems reasonable to allow a designated initializer to omit the name. GCC has no problem unambiguously resolving the field reference a.x, so it seems like GCC should unambiguously resolve the designated initializer .x = expression. In case it helps: $ gcc -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.2-1' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-cld --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.3.2 (Debian 4.3.2-1) -- Summary: Cannot use nested designated initializer with unnamed inner aggregate Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: josh at freedesktop dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38019