This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/14713] New: unbraced initialization of a flexible array member


When initializing a flexible array member with an unbraced list initializer gcc
complains. I know that if I use the fully braced form a1={1,{2,3}} then it is
ok. Why is the unbraced form accepting only one element for a flexible array(of
size=0) when for a normal array it accepts more that one?(i.e accept as many
elements as there are in the normal array).
 
-----------with a flexible array---------------------------
henry@zulu:~/test> more t2.c
#include <stdio.h>
struct A {
        int x;
        int y [];
};
struct A a1 = {1, 2,3};
int main(){
  printf("%d %d %d\n", a1.x, a1.y[0], a1.y[1] );
  return 0;
}
henry@zulu:~/test> gcc t2.c -Wall
t2.c:6: warning: missing braces around initializer
t2.c:6: warning: (near initialization for `a1.y')
t2.c:6: warning: excess elements in struct initializer
t2.c:6: warning: (near initialization for `a1')
henry@zulu:~/test> ./a.out
1 2 1030426625

-----------with a normal array ---------------------------
henry@zulu:~/test> more t2b.c
#include <stdio.h>
struct A {
        int x;
        int y [2];
};
struct A a1 = {1, 2,3};
int main(){
  printf("%d %d %d\n", a1.x, a1.y[0], a1.y[1] );
  return 0;
}
henry@zulu:~/test> gcc t2b.c -Wall
t2b.c:6: warning: missing braces around initializer
t2b.c:6: warning: (near initialization for `a1.y')
henry@zulu:~/test> ./a.out
1 2 3
--------------------------------------------------
henry@zulu:~/test> gcc -v
Reading specs from /usr/lib/gcc-lib/powerpc-suse-linux/3.2.2/specs
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man
--libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --enable-libgcj
--with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib
--enable-shared --enable-__cxa_atexit powerpc-suse-linux
Thread model: posix
gcc version 3.2.2

-- 
           Summary: unbraced initialization of a flexible array member
           Product: gcc
           Version: 3.2.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: henryhack101 at netscape dot net
                CC: gcc-bugs at gcc dot gnu dot org


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]