This is the mail archive of the gcc@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]

Re: warn/croak on "string" "string" auto-joins


On Wed, 2004-08-18 at 12:12, Chris Jefferson wrote:
> Dave Korn wrote:
> 
>  >
>  >>>>This would have helped early and is good practice:
>  >>>>
>  >>>>char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May",
>  >>
>  >>"Jun", "Jul",
>  >>
>  >>>>"Aug" "Sep", "Oct", "Nov", "Dec"};
>  >>>>
>  >>>>--> high probability warning
>  >>>
>  >>>I'm not sure I understand, what does "high probability
>  >>
>  >>warning" mean?
>  >>
>  >>>I get no errors/warnings from the following:
>  >>>
>  >>>#include <stdio.h>
>  >>>int main( void )
>  >>>{
>  >>>  char *months[15] = {"Jan", "Feb", "Mar", "Apr", "May",
>  >>
>  >>"Jun", "Jul",
>  >>
>  >>>"Aug" "Sep", "Oct", "Nov", "Dec"};
>  >>>  printf("7: %s\n", months[8]);
>  >>>  return 0;
>  >>>}
>  >>>
>  >>>compiled with 'gcc -Wall -pedantic -ansi', using GCC 3.3.3.
>  >>
>  >>Hmm, I could have sworn that a mismatch in array dimensions
>  >>does emit a warning (too many initializers do error out "como").
>  >>Looks like this is not the case. Sorry for bothering you :-(
>  >
>  >
>  >  But it has too *few* initialisers!
>  >
> While not exactly what was asked for in the first place, it would seem 
> to me this kind of problem (giving too few initalisers to a fixed length 
> array) should definatly emit a warning.. would this be hard to do / can 
> anyone come up with a sensible reason to give too few initalisers?

While not a C standard guru, I think this is allowed and compatible with
the C99 initialization rules. Specifically, section 6.7.8, p125,
paragraphs 17, 19 and 10 which means that the end of your char *array is
initialized with null values.

regards,
Mathieu

> 
> Chris
-- 
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>


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