* 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 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 23:20 ` Robert Dewar
2004-08-17 23:02 ` Robert Dewar
1 sibling, 2 replies; 34+ messages in thread
From: Zack Weinberg @ 2004-08-17 17:52 UTC (permalink / raw)
To: Adam Monsen; +Cc: gcc
Adam Monsen <haircut@gmail.com> writes:
> String auto-joins can be dangerous. Is there a way to tell the
> compiler to warn/croak when an auto-join occurs?
There is not, and without a way for the programmer to make clear that
a given use of string-constant concatenation is intentional, I am
reluctant to add one.
zw
^ permalink raw reply [flat|nested] 34+ messages in thread
* RE: warn/croak on "string" "string" auto-joins
2004-08-17 17:52 ` Zack Weinberg
@ 2004-08-17 18:02 ` Dave Korn
2004-08-17 18:09 ` Zack Weinberg
2004-08-17 23:25 ` Robert Dewar
2004-08-17 23:20 ` Robert Dewar
1 sibling, 2 replies; 34+ messages in thread
From: Dave Korn @ 2004-08-17 18:02 UTC (permalink / raw)
To: 'Zack Weinberg', 'Adam Monsen'; +Cc: gcc
> -----Original Message-----
> From: gcc-owner On Behalf Of Zack Weinberg
> Sent: 17 August 2004 18:49
> Adam Monsen writes:
>
> > String auto-joins can be dangerous. Is there a way to tell the
> > compiler to warn/croak when an auto-join occurs?
>
> There is not, and without a way for the programmer to make clear that
> a given use of string-constant concatenation is intentional, I am
> reluctant to add one.
>
> zw
Yeh. What if you really *did* want to talk about your "Crayon-line
drawing routines"?
More seriously though, I don't see why there shouldn't be one, but rather
than make coders go through and lint-markup every place where we really
meant to concat two strings in a macro (one of which has only just been
en-quoted), maybe the warning should just default to "off"?
cheers,
DaveK
--
Can't think of a witty .sigline today....
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
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:24 ` Adam Monsen
2004-08-17 23:25 ` Robert Dewar
1 sibling, 2 replies; 34+ messages in thread
From: Zack Weinberg @ 2004-08-17 18:09 UTC (permalink / raw)
To: Dave Korn; +Cc: 'Adam Monsen', gcc
"Dave Korn" <dk@artimi.com> writes:
> More seriously though, I don't see why there shouldn't be one, but rather
> than make coders go through and lint-markup every place where we really
> meant to concat two strings in a macro (one of which has only just been
> en-quoted), maybe the warning should just default to "off"?
I'm wondering how useful it would be without lint-markup even if it
*did* default to off.
zw
^ permalink raw reply [flat|nested] 34+ messages in thread
* RE: warn/croak on "string" "string" auto-joins
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
1 sibling, 2 replies; 34+ messages in thread
From: Dave Korn @ 2004-08-17 18:12 UTC (permalink / raw)
To: 'Zack Weinberg'; +Cc: 'Adam Monsen', gcc
> -----Original Message-----
> From: Zack Weinberg
> Sent: 17 August 2004 19:01
> "Dave Korn" writes:
>
> > More seriously though, I don't see why there shouldn't be
> one, but rather
> > than make coders go through and lint-markup every place
> where we really
> > meant to concat two strings in a macro (one of which has
> only just been
> > en-quoted), maybe the warning should just default to "off"?
>
> I'm wondering how useful it would be without lint-markup even if it
> *did* default to off.
>
> zw
Point taken. Maybe a more useful set of options than "on/off" would be
"on/off/off in system headers but on in application files"
cheers,
DaveK
--
Can't think of a witty .sigline today....
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-17 18:12 ` Dave Korn
@ 2004-08-17 18:20 ` Andrew Pinski
2004-08-17 18:55 ` Zack Weinberg
1 sibling, 0 replies; 34+ messages in thread
From: Andrew Pinski @ 2004-08-17 18:20 UTC (permalink / raw)
To: Dave Korn; +Cc: 'Zack Weinberg', 'Adam Monsen', gcc
On Aug 17, 2004, at 11:07 AM, Dave Korn wrote:
> Point taken. Maybe a more useful set of options than "on/off" would
> be
> "on/off/off in system headers but on in application files"
I would say no because this is required by the standard.....
Now if the person was using K&R C, I think they should be using
-Wtraditional
anyways as it warns about it, since it was added for C90.
--Pinski
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-17 18:09 ` Zack Weinberg
2004-08-17 18:12 ` Dave Korn
@ 2004-08-17 18:24 ` Adam Monsen
1 sibling, 0 replies; 34+ messages in thread
From: Adam Monsen @ 2004-08-17 18:24 UTC (permalink / raw)
To: Zack Weinberg; +Cc: Dave Korn, gcc
On Tue, 17 Aug 2004 11:01:11 -0700, Zack Weinberg <zack@codesourcery.com> wrote:
> "Dave Korn" <dk@artimi.com> writes:
>
> > More seriously though, I don't see why there shouldn't be one, but rather
> > than make coders go through and lint-markup every place where we really
> > meant to concat two strings in a macro (one of which has only just been
> > en-quoted), maybe the warning should just default to "off"?
>
> I'm wondering how useful it would be without lint-markup even if it
> *did* default to off.
It would help find the bug I mentioned, for instance. That would be
useful to me.
How 'bout:
#pragma concatstrings 0
--
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 18:12 ` Dave Korn
2004-08-17 18:20 ` Andrew Pinski
@ 2004-08-17 18:55 ` Zack Weinberg
1 sibling, 0 replies; 34+ messages in thread
From: Zack Weinberg @ 2004-08-17 18:55 UTC (permalink / raw)
To: Dave Korn; +Cc: 'Adam Monsen', gcc
"Dave Korn" <dk@artimi.com> writes:
>> -----Original Message-----
>> From: Zack Weinberg
>> Sent: 17 August 2004 19:01
>
>> "Dave Korn" writes:
>>
>> > More seriously though, I don't see why there shouldn't be
>> one, but rather
>> > than make coders go through and lint-markup every place
>> where we really
>> > meant to concat two strings in a macro (one of which has
>> only just been
>> > en-quoted), maybe the warning should just default to "off"?
>>
>> I'm wondering how useful it would be without lint-markup even if it
>> *did* default to off.
>>
>> zw
>
>
> Point taken. Maybe a more useful set of options than "on/off" would be
> "on/off/off in system headers but on in application files"
All warnings are off in system headers anyway.
Why don't you and Adam talk this over and come up with a specification
that would work for you?
zw
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-17 17:37 warn/croak on "string" "string" auto-joins Adam Monsen
2004-08-17 17:52 ` Zack Weinberg
@ 2004-08-17 23:02 ` Robert Dewar
1 sibling, 0 replies; 34+ messages in thread
From: Robert Dewar @ 2004-08-17 23:02 UTC (permalink / raw)
To: Adam Monsen; +Cc: gcc
Adam Monsen wrote:
> String auto-joins can be dangerous. Is there a way to tell the
> compiler to warn/croak when an auto-join occurs?
Seems a bit odd to warn on a perfectly normal non-suspicious
usage.
>
> For instance, find the bug in this code:
>
> char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
> "Aug" "Sep", "Oct", "Nov", "Dec"};
To me there is no bug, though for sure I can guess that the programmer
did not mean to make the 8'th entry 6 characters long.
>
> If not, I'd like to suggest a way to ask the compiler to strictly
> check for this.
I suppose a warning flag would be innocuous, provided it was not
included in -Wall.
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-17 17:52 ` Zack Weinberg
2004-08-17 18:02 ` Dave Korn
@ 2004-08-17 23:20 ` Robert Dewar
2004-08-17 23:25 ` Stan Shebs
` (3 more replies)
1 sibling, 4 replies; 34+ messages in thread
From: Robert Dewar @ 2004-08-17 23:20 UTC (permalink / raw)
To: Zack Weinberg; +Cc: Adam Monsen, gcc
Zack Weinberg wrote:
> Adam Monsen <haircut@gmail.com> writes:
>
>
>>String auto-joins can be dangerous. Is there a way to tell the
>>compiler to warn/croak when an auto-join occurs?
>
>
> There is not, and without a way for the programmer to make clear that
> a given use of string-constant concatenation is intentional, I am
> reluctant to add one.
I would think the reasonable condition for the warning is that no
line feed appears between the two strings, which is indeed unusual
usage.
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-17 18:02 ` Dave Korn
2004-08-17 18:09 ` Zack Weinberg
@ 2004-08-17 23:25 ` Robert Dewar
1 sibling, 0 replies; 34+ messages in thread
From: Robert Dewar @ 2004-08-17 23:25 UTC (permalink / raw)
To: Dave Korn; +Cc: 'Zack Weinberg', 'Adam Monsen', gcc
Dave Korn wrote:
> More seriously though, I don't see why there shouldn't be one, but rather
> than make coders go through and lint-markup every place where we really
> meant to concat two strings in a macro (one of which has only just been
> en-quoted), maybe the warning should just default to "off"?
I cannot imagine for a moment that anyone would countenance this
warning beingf "on" by default!
>
> cheers,
> DaveK
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
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
` (2 subsequent siblings)
3 siblings, 1 reply; 34+ messages in thread
From: Stan Shebs @ 2004-08-17 23:25 UTC (permalink / raw)
To: Robert Dewar; +Cc: Zack Weinberg, Adam Monsen, gcc
Robert Dewar wrote:
> Zack Weinberg wrote:
>
>> Adam Monsen <haircut@gmail.com> writes:
>>
>>
>>> String auto-joins can be dangerous. Is there a way to tell the
>>> compiler to warn/croak when an auto-join occurs?
>>
>>
>>
>> There is not, and without a way for the programmer to make clear that
>> a given use of string-constant concatenation is intentional, I am
>> reluctant to add one.
>
>
> I would think the reasonable condition for the warning is that no
> line feed appears between the two strings, which is indeed unusual
> usage.
Not that unusual, for instance consider a macro that expands into
"%d" or "%ld", used in printf("before " MACRO " after", int_or_long)
and the like. Our very own code uses this trick even.
Stan
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-17 23:25 ` Stan Shebs
@ 2004-08-18 0:21 ` Robert Dewar
0 siblings, 0 replies; 34+ messages in thread
From: Robert Dewar @ 2004-08-18 0:21 UTC (permalink / raw)
To: Stan Shebs; +Cc: Zack Weinberg, Adam Monsen, gcc
Stan Shebs wrote:
> Not that unusual, for instance consider a macro that expands into
> "%d" or "%ld", used in printf("before " MACRO " after", int_or_long)
> and the like. Our very own code uses this trick even.
Right, perfectly reasonable. I would certainly never use this
warning flag myself. I suppose you could react to the above comment
by saying that the only time you give the warning is when two
strings appear together explicitly in an original source line,
but that's getting complex.
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-17 23:20 ` Robert Dewar
2004-08-17 23:25 ` Stan Shebs
@ 2004-08-18 2:43 ` Mike Stump
2004-08-18 13:16 ` Paul Koning
2004-08-19 21:20 ` Kai Henningsen
3 siblings, 0 replies; 34+ messages in thread
From: Mike Stump @ 2004-08-18 2:43 UTC (permalink / raw)
To: Robert Dewar; +Cc: gcc, Adam Monsen, Zack Weinberg
On Aug 17, 2004, at 4:00 PM, Robert Dewar wrote:
> I would think the reasonable condition for the warning is that no
> line feed appears between the two strings, which is indeed unusual
> usage.
And that a literal ``" "'' appears in the input stream... Most uses
are likely to have comments, macro fun, newlines, tabs, multiple
spaces....
:-)
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-17 23:20 ` Robert Dewar
2004-08-17 23:25 ` Stan Shebs
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
3 siblings, 1 reply; 34+ messages in thread
From: Paul Koning @ 2004-08-18 13:16 UTC (permalink / raw)
To: dewar; +Cc: zack, haircut, gcc
>>>>> "Robert" == Robert Dewar <dewar@gnat.com> writes:
Robert> Zack Weinberg wrote:
>> Adam Monsen <haircut@gmail.com> writes:
>>
>>
>>> String auto-joins can be dangerous. Is there a way to tell the
>>> compiler to warn/croak when an auto-join occurs?
>>
>>
>> There is not, and without a way for the programmer to make clear
>> that a given use of string-constant concatenation is intentional,
>> I am reluctant to add one.
Robert> I would think the reasonable condition for the warning is
Robert> that no line feed appears between the two strings, which is
Robert> indeed unusual usage.
It's usual in macros.
paul
^ permalink raw reply [flat|nested] 34+ messages in thread
* RE: warn/croak on "string" "string" auto-joins
2004-08-18 13:16 ` Paul Koning
@ 2004-08-18 18:08 ` Dave Korn
0 siblings, 0 replies; 34+ messages in thread
From: Dave Korn @ 2004-08-18 18:08 UTC (permalink / raw)
To: 'Paul Koning', dewar; +Cc: zack, haircut, gcc
> -----Original Message-----
> From: gcc-owner On Behalf Of Paul Koning
> Sent: 18 August 2004 14:10
> >>>>> "Robert" == Robert Dewar <dewar@gnat.com> writes:
>
> Robert> Zack Weinberg wrote:
> >> Adam Monsen <haircut@gmail.com> writes:
> >>
> >>
> >>> String auto-joins can be dangerous. Is there a way to tell the
> >>> compiler to warn/croak when an auto-join occurs?
> >>
> >>
> >> There is not, and without a way for the programmer to make clear
> >> that a given use of string-constant concatenation is intentional,
> >> I am reluctant to add one.
>
> Robert> I would think the reasonable condition for the warning is
> Robert> that no line feed appears between the two strings, which is
> Robert> indeed unusual usage.
>
> It's usual in macros.
>
> paul
Yep. I would have thought that concatenation that *is* across a linefeed
is most likely to be the case when someone's accidentally omitted a comma
from a list of strings.
cheers,
DaveK
--
Can't think of a witty .sigline today....
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-17 23:20 ` Robert Dewar
` (2 preceding siblings ...)
2004-08-18 13:16 ` Paul Koning
@ 2004-08-19 21:20 ` Kai Henningsen
2004-08-19 21:31 ` Chris Jefferson
` (3 more replies)
3 siblings, 4 replies; 34+ messages in thread
From: Kai Henningsen @ 2004-08-19 21:20 UTC (permalink / raw)
To: gcc
dewar@gnat.com (Robert Dewar) wrote on 17.08.04 in <41228E08.2010008@gnat.com>:
> Zack Weinberg wrote:
>
> > Adam Monsen <haircut@gmail.com> writes:
> >
> >
> >>String auto-joins can be dangerous. Is there a way to tell the
> >>compiler to warn/croak when an auto-join occurs?
> >
> >
> > There is not, and without a way for the programmer to make clear that
> > a given use of string-constant concatenation is intentional, I am
> > reluctant to add one.
>
> I would think the reasonable condition for the warning is that no
> line feed appears between the two strings, which is indeed unusual
> usage.
Without intervening line feed is pretty much the *only* way I use
automatic concatenation. I can't immediately think of a single good reason
to use it *with* intervening line feed ...
MfG Kai
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
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
` (2 subsequent siblings)
3 siblings, 1 reply; 34+ messages in thread
From: Chris Jefferson @ 2004-08-19 21:31 UTC (permalink / raw)
Cc: gcc
>
>Without intervening line feed is pretty much the *only* way I use
>automatic concatenation. I can't immediately think of a single good reason
>to use it *with* intervening line feed ...
>
>MfG Kai
>
"When you want to keep your line length short, but write a very long "
"string then automatic concatentation can be very useful.. I use it all "
"the time, but maybe this suggests that I often have too long embedded "
"strings in my C++ code"
Azumanga
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-19 21:20 ` Kai Henningsen
2004-08-19 21:31 ` Chris Jefferson
@ 2004-08-19 21:32 ` Michael N. Moran
2004-08-19 21:53 ` Janis Johnson
2004-08-19 23:23 ` Florian Weimer
3 siblings, 0 replies; 34+ messages in thread
From: Michael N. Moran @ 2004-08-19 21:32 UTC (permalink / raw)
Cc: gcc
Kai Henningsen wrote:
> Without intervening line feed is pretty much the *only* way I use
> automatic concatenation. I can't immediately think of a single good reason
> to use it *with* intervening line feed ...
I use this form occasionally just to keep
long strings formatted well for source code.
YMMV
printf( "This is the first line"
"and this is the second.\n"
);
--
Michael N. Moran (h) 770 516 7918
5009 Old Field Ct. (c) 678 521 5460
Kennesaw, GA, USA 30144 http://mnmoran.org
"... abstractions save us time working, but they don't
save us time learning."
Joel Spolsky, The Law of Leaky Abstractions
The Beatles were wrong: 1 & 1 & 1 is 1
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-19 21:20 ` Kai Henningsen
2004-08-19 21:31 ` Chris Jefferson
2004-08-19 21:32 ` Michael N. Moran
@ 2004-08-19 21:53 ` Janis Johnson
2004-08-19 23:23 ` Florian Weimer
3 siblings, 0 replies; 34+ messages in thread
From: Janis Johnson @ 2004-08-19 21:53 UTC (permalink / raw)
To: Kai Henningsen; +Cc: gcc
On Thu, Aug 19, 2004 at 07:20:00PM +0200, Kai Henningsen wrote:
> Without intervening line feed is pretty much the *only* way I use
> automatic concatenation. I can't immediately think of a single good reason
> to use it *with* intervening line feed ...
GCC itself is full of things like
fprintf (STREAM, ", " HOST_WIDE_INT_PRINT_DEC "\n", size_);
where HOST_WIDE_INT_PRINT_DEC is a string literal.
Janis
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-19 21:20 ` Kai Henningsen
` (2 preceding siblings ...)
2004-08-19 21:53 ` Janis Johnson
@ 2004-08-19 23:23 ` Florian Weimer
2004-08-20 16:49 ` Kai Henningsen
3 siblings, 1 reply; 34+ messages in thread
From: Florian Weimer @ 2004-08-19 23:23 UTC (permalink / raw)
To: Kai Henningsen; +Cc: gcc
* Kai Henningsen:
> Without intervening line feed is pretty much the *only* way I use
> automatic concatenation. I can't immediately think of a single good reason
> to use it *with* intervening line feed ...
What about the macros for format specifiers defined in <inttypes.h>?
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-19 21:31 ` Chris Jefferson
@ 2004-08-20 16:25 ` Kai Henningsen
0 siblings, 0 replies; 34+ messages in thread
From: Kai Henningsen @ 2004-08-20 16:25 UTC (permalink / raw)
To: gcc
caj@cs.york.ac.uk (Chris Jefferson) wrote on 19.08.04 in <41251677.9060704@cs.york.ac.uk>:
> >Without intervening line feed is pretty much the *only* way I use
> >automatic concatenation. I can't immediately think of a single good reason
> >to use it *with* intervening line feed ...
> "When you want to keep your line length short, but write a very long "
> "string then automatic concatentation can be very useful.. I use it all "
> "the time, but maybe this suggests that I often have too long embedded "
> "strings in my C++ code"
True ... that comes up rarely enough that I didn't manage to think of it.
(Especially as my personal experience is that overlong lines usually read
better when not artificially linewrapped.)
Come to think of it, another (hopefully also rare) case is asm statements.
MfG Kai
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-19 23:23 ` Florian Weimer
@ 2004-08-20 16:49 ` Kai Henningsen
0 siblings, 0 replies; 34+ messages in thread
From: Kai Henningsen @ 2004-08-20 16:49 UTC (permalink / raw)
To: gcc
fw@deneb.enyo.de (Florian Weimer) wrote on 20.08.04 in <87hdqy4txo.fsf@deneb.enyo.de>:
> * Kai Henningsen:
>
> > Without intervening line feed is pretty much the *only* way I use
> > automatic concatenation. I can't immediately think of a single good reason
> > to use it *with* intervening line feed ...
>
> What about the macros for format specifiers defined in <inttypes.h>?
What about them? Surely there's no linefeed involved?
MfG Kai
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-18 10:55 ` Chris Jefferson
2004-08-18 11:17 ` Mathieu Lacage
2004-08-18 12:55 ` Andreas Schwab
@ 2004-08-20 11:27 ` Per Abrahamsen
2 siblings, 0 replies; 34+ messages in thread
From: Per Abrahamsen @ 2004-08-20 11:27 UTC (permalink / raw)
To: gcc
Chris Jefferson <caj@cs.york.ac.uk> writes:
> 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?
char buffer[1024] = "hello";
strcat (buffer, " world\n");
Isn't code like that quite common?
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-18 11:36 ` Mathieu Lacage
@ 2004-08-18 14:07 ` Robert Dewar
0 siblings, 0 replies; 34+ messages in thread
From: Robert Dewar @ 2004-08-18 14:07 UTC (permalink / raw)
To: Mathieu Lacage; +Cc: Chris Jefferson, gcc
The latest post on this thread had 7 levels of nested
quotes. This business of casually quoting the entire
message results in a quadratic accumulation of junk.
We really don't need the whole thread in every message.
It would be nice if people were a little bit more
selective in quotations. The message in question
by the way, after quoting over a hundred lines of
text with 7 levels of quotes, adds precisely three
lines of original text.
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-18 10:55 ` Chris Jefferson
2004-08-18 11:17 ` Mathieu Lacage
@ 2004-08-18 12:55 ` Andreas Schwab
2004-08-20 11:27 ` Per Abrahamsen
2 siblings, 0 replies; 34+ messages in thread
From: Andreas Schwab @ 2004-08-18 12:55 UTC (permalink / raw)
To: Chris Jefferson
Cc: Dave Korn, 'Gabor Greif', 'Adam Monsen', gcc
Chris Jefferson <caj@cs.york.ac.uk> writes:
> 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?
We already have such a warning (-Wmissing-field-initializers), but it only
triggers for partially initialized structures, not arrays.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, MaxfeldstraÃe 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-18 11:19 ` Chris Jefferson
@ 2004-08-18 11:36 ` Mathieu Lacage
2004-08-18 14:07 ` Robert Dewar
0 siblings, 1 reply; 34+ messages in thread
From: Mathieu Lacage @ 2004-08-18 11:36 UTC (permalink / raw)
To: Chris Jefferson; +Cc: gcc
On Wed, 2004-08-18 at 13:10, Chris Jefferson wrote:
> Mathieu Lacage wrote:
>
> >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.
> >
> >
> >
> I'm also fairly certain that it is legal.. however the purpose of
> warnings is to emit messages about things which while legal someone
> probably didn't mean to write :) and this would I think apply almost
> always in this case, and would go some way to fixing the original
> problem I think.
I am afraid that it is fairly common for certain programmers to write
this:
type array[] = {0, };
Mathieu
--
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-18 11:17 ` Mathieu Lacage
@ 2004-08-18 11:19 ` Chris Jefferson
2004-08-18 11:36 ` Mathieu Lacage
0 siblings, 1 reply; 34+ messages in thread
From: Chris Jefferson @ 2004-08-18 11:19 UTC (permalink / raw)
To: Mathieu Lacage; +Cc: gcc
Mathieu Lacage wrote:
>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.
>
>
>
I'm also fairly certain that it is legal.. however the purpose of
warnings is to emit messages about things which while legal someone
probably didn't mean to write :) and this would I think apply almost
always in this case, and would go some way to fixing the original
problem I think.
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-18 10:55 ` Chris Jefferson
@ 2004-08-18 11:17 ` Mathieu Lacage
2004-08-18 11:19 ` Chris Jefferson
2004-08-18 12:55 ` Andreas Schwab
2004-08-20 11:27 ` Per Abrahamsen
2 siblings, 1 reply; 34+ messages in thread
From: Mathieu Lacage @ 2004-08-18 11:17 UTC (permalink / raw)
To: Chris Jefferson; +Cc: gcc
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>
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-18 10:15 ` Dave Korn
@ 2004-08-18 10:55 ` Chris Jefferson
2004-08-18 11:17 ` Mathieu Lacage
` (2 more replies)
0 siblings, 3 replies; 34+ messages in thread
From: Chris Jefferson @ 2004-08-18 10:55 UTC (permalink / raw)
To: Dave Korn; +Cc: 'Gabor Greif', 'Adam Monsen', gcc
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?
Chris
^ permalink raw reply [flat|nested] 34+ messages in thread
* RE: warn/croak on "string" "string" auto-joins
2004-08-18 0:49 ` Gabor Greif
@ 2004-08-18 10:15 ` Dave Korn
2004-08-18 10:55 ` Chris Jefferson
0 siblings, 1 reply; 34+ messages in thread
From: Dave Korn @ 2004-08-18 10:15 UTC (permalink / raw)
To: 'Gabor Greif', 'Adam Monsen'; +Cc: gcc
> -----Original Message-----
> From: gcc-owner On Behalf Of Gabor Greif
> Sent: 18 August 2004 01:45
> >> 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!
cheers,
DaveK
--
Can't think of a witty .sigline today....
^ permalink raw reply [flat|nested] 34+ messages in thread
* Re: warn/croak on "string" "string" auto-joins
2004-08-18 0:22 ` Adam Monsen
@ 2004-08-18 0:49 ` Gabor Greif
2004-08-18 10:15 ` Dave Korn
0 siblings, 1 reply; 34+ messages in thread
From: Gabor Greif @ 2004-08-18 0:49 UTC (permalink / raw)
To: Adam Monsen; +Cc: gcc
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/
^ 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
2004-08-18 0:49 ` Gabor Greif
0 siblings, 1 reply; 34+ messages in thread
From: Adam Monsen @ 2004-08-18 0:22 UTC (permalink / raw)
To: Gabor Greif; +Cc: gcc
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.
> 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.
--
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).