This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
gcc 2.95.1 Spurious Warning (minor)
- To: gcc-bugs at gcc dot gnu dot org
- Subject: gcc 2.95.1 Spurious Warning (minor)
- From: "Mark G. Adams" <madams at livepage dot com>
- Date: Thu, 26 Aug 1999 13:26:52 -0400
- Organization: LivePage
I ran across these warnings in a piece of code similar to this one:
~/test$> gcc -Wall init.c
init.c:4: warning: braces around scalar initializer
init.c:4: warning: (near initialization for `str[0]')
init.c:5: warning: braces around scalar initializer
init.c:5: warning: (near initialization for `str[1]')
init.c:6: warning: braces around scalar initializer
init.c:6: warning: (near initialization for `str[2]')
-----------
#include <stdio.h>
char *str[] = {
{ "foo" },
{ "bar" },
{ "foobar" }
};
int main( ) {
printf( "In main. Str[2]: %s\n", str[2] );
return 0;
}
------------
Now, the {}'s around the strings clearly are not required. However, from my
reading of the draft C99 standard, the compiler shouldn't be warning about
their presence either. Specifically, I'm referring to section 6.7.8.14, which
states:
An array of character type may be initialized by a character string
literal, optionally enclosed in braces.
Thus, having the {}'s around the string is accepted by the standard. Is the
warning being emitted deliberately?
//Mark
--
Mark G. Adams
Software Developer
LivePage Corporation
Waterloo, Ontario, Canada
Email: madams@livepage.com