public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/14713] New: unbraced initialization of a flexible array member
@ 2004-03-24  7:27 henryhack101 at netscape dot net
  2004-03-24 15:46 ` [Bug c/14713] " bangerth at dealii dot org
  0 siblings, 1 reply; 2+ messages in thread
From: henryhack101 at netscape dot net @ 2004-03-24  7:27 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/14713] unbraced initialization of a flexible array member
  2004-03-24  7:27 [Bug c/14713] New: unbraced initialization of a flexible array member henryhack101 at netscape dot net
@ 2004-03-24 15:46 ` bangerth at dealii dot org
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth at dealii dot org @ 2004-03-24 15:46 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-03-24 15:46 -------
gcc 3.3 and later report this: 
 
g/x> /home/bangerth/bin/gcc-3.3.4-pre/bin/gcc -c x.c 
x.c:6: warning: excess elements in struct initializer 
x.c:6: warning: (near initialization for `a1') 
 
This is also what icc reports, so I assume that it is the correct 
error warning message. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |3.3


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-03-24 15:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-24  7:27 [Bug c/14713] New: unbraced initialization of a flexible array member henryhack101 at netscape dot net
2004-03-24 15:46 ` [Bug c/14713] " bangerth at dealii dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).