warn/croak on "string" "string" auto-joins
Gabor Greif
gabor@mac.com
Tue Aug 17 23:26:00 GMT 2004
Adam Monsen <haircut at gmail dot com> wrote:
> String auto-joins can be dangerous. Is there a way to tell the
> compiler to warn/croak when an auto-join occurs?
>
> For instance, find the bug in this code:
>
> char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
> "Aug" "Sep", "Oct", "Nov", "Dec"};
>
> If not, I'd like to suggest a way to ask the compiler to strictly
> check for this.
The compiler cannot shield you from all programmer errors.
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
Cheers,
Gabor
PS: I often assemble longer (format) strings from smaller ones
by means of macros, so if this ever to become a warning I'd
prefer to exclude macro-expanded occurrences.
More information about the Gcc
mailing list