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]

gcc 2.95.1 Spurious Warning (minor)


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


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