public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Gabor Greif <gabor@mac.com>
To: Adam Monsen <haircut@gmail.com>
Cc: gcc@gcc.gnu.org
Subject: Re: warn/croak on "string" "string" auto-joins
Date: Wed, 18 Aug 2004 00:49:00 -0000	[thread overview]
Message-ID: <D6DD1F3E-F0AF-11D8-A3A2-000393A34C6C@mac.com> (raw)
In-Reply-To: <9ebd65110408171721146dd77@mail.gmail.com>

Am Mittwoch den, 18. August 2004, um 02:21, schrieb Adam Monsen:

> Hi Gabor,
>
> Thanks for your input!
>
> On Wed, 18 Aug 2004 01:25:10 +0200, Gabor Greif <gabor@mac.com> wrote:
>> 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.
>
> Agreed.
>
>> 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 :-(

>
>> 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.
>
> But you currently have no use for the warning, correct? Or, do you
> feel it is useful? I'm confused.

No use for the warning, as I have never made this particular error,
but it does indeed look hard to debug. So if it occurs in the source
like in your example I would not mind to be warned by the compiler.
However in case the concatenation comes from macro expansion,
warning on it would be bad.

   Gabor


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

  reply	other threads:[~2004-08-18  0:44 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-17 23:26 Gabor Greif
2004-08-18  0:22 ` Adam Monsen
2004-08-18  0:49   ` Gabor Greif [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
2004-08-17 17:37 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D6DD1F3E-F0AF-11D8-A3A2-000393A34C6C@mac.com \
    --to=gabor@mac.com \
    --cc=gcc@gcc.gnu.org \
    --cc=haircut@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).