public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* warn/croak on "string" "string" auto-joins
@ 2004-08-17 17:37 Adam Monsen
  2004-08-17 17:52 ` Zack Weinberg
  2004-08-17 23:02 ` Robert Dewar
  0 siblings, 2 replies; 34+ messages in thread
From: Adam Monsen @ 2004-08-17 17:37 UTC (permalink / raw)
  To: gcc

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.

-- 
Adam Monsen <adamm@wazamatta.com>
http://adammonsen.com/

^ permalink raw reply	[flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
@ 2004-08-17 23:26 Gabor Greif
  2004-08-18  0:22 ` Adam Monsen
  0 siblings, 1 reply; 34+ messages in thread
From: Gabor Greif @ 2004-08-17 23:26 UTC (permalink / raw)
  To: gcc; +Cc: Adam Monsen

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.

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2004-08-20 15:35 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-17 17:37 warn/croak on "string" "string" auto-joins Adam Monsen
2004-08-17 17:52 ` Zack Weinberg
2004-08-17 18:02   ` Dave Korn
2004-08-17 18:09     ` Zack Weinberg
2004-08-17 18:12       ` Dave Korn
2004-08-17 18:20         ` Andrew Pinski
2004-08-17 18:55         ` Zack Weinberg
2004-08-17 18:24       ` Adam Monsen
2004-08-17 23:25     ` Robert Dewar
2004-08-17 23:20   ` Robert Dewar
2004-08-17 23:25     ` Stan Shebs
2004-08-18  0:21       ` Robert Dewar
2004-08-18  2:43     ` Mike Stump
2004-08-18 13:16     ` Paul Koning
2004-08-18 18:08       ` Dave Korn
2004-08-19 21:20     ` Kai Henningsen
2004-08-19 21:31       ` Chris Jefferson
2004-08-20 16:25         ` Kai Henningsen
2004-08-19 21:32       ` Michael N. Moran
2004-08-19 21:53       ` Janis Johnson
2004-08-19 23:23       ` Florian Weimer
2004-08-20 16:49         ` Kai Henningsen
2004-08-17 23:02 ` Robert Dewar
2004-08-17 23:26 Gabor Greif
2004-08-18  0:22 ` Adam Monsen
2004-08-18  0:49   ` Gabor Greif
2004-08-18 10:15     ` Dave Korn
2004-08-18 10:55       ` Chris Jefferson
2004-08-18 11:17         ` Mathieu Lacage
2004-08-18 11:19           ` Chris Jefferson
2004-08-18 11:36             ` Mathieu Lacage
2004-08-18 14:07               ` Robert Dewar
2004-08-18 12:55         ` Andreas Schwab
2004-08-20 11:27         ` Per Abrahamsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).