This is the mail archive of the
mailing list for the GCC project.
What does zero-length array mean at file scope?
- From: Dave Korn <dave dot korn dot cygwin at googlemail dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Sun, 24 May 2009 01:58:53 +0100
- Subject: What does zero-length array mean at file scope?
I found something rather odd in testcase gcc.c-torture/execute/20030811-1.c:
> /* Origin: PR target/11535 from H. J. Lu <firstname.lastname@example.org> */
> void vararg (int i, ...)
> (void) i;
> int i0, i1;
> void test1 (void)
> int a = (int) (long long) __builtin_return_address (0);
> vararg (0, a);
> void test2 (void)
> i0 = (int) (long long) __builtin_return_address (0);
> void test3 (void)
> i1 = (int) (long long) __builtin_return_address (0);
> void test4 (void)
> volatile long long a = (long long) __builtin_return_address (0);
> i0 = (int) a;
ELF GAS/LD seem happy enough when presented with a ".comm foo,0" directive,
but PE does rather literally what you asked, and gives you no data object,
leading to i0 in the above being an undefined reference at link time.
What is supposed to happen here? How much space is the compiler meant to
allocate to i0? Where does the data go when it gets stored to i0?
I've read http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html about six times
and can't see anywhere it even hints that you can use this syntax anywhere
except as the trailing member of a struct. When I look at the original
PR11535, the testcases in there are all similar but have array size  and
try to assign the builtin_return_address result to array - that's clearly
valid, and quite different from how this testcase ended up.
So, is the testcase invalid, and should the compiler be warning about this
declaration? I couldn't get any complaint out of it even with "-W -Wall
-Wextra -pedantic -std=c89"? Or should the linker be allocating some space
for this zero-sized common?