|
From: | Dave Hansen |
Subject: | Re: [avr-gcc-list] Bizarre string problem |
Date: | Fri, 10 Sep 2004 09:31:18 -0400 |
From: address@hidden (Joerg Wunsch) [...]
"Dave Hansen" <address@hidden> wrote:
[...]
> The way I read this is > > char t[1] = "Thanks for all the fish."; > > is legal and will initialize the first (and only) element of t to 'T'. That's the fun about standards. ;-) The way I read the above is that this wouldn't be allowed, since the optional clause ``if there is room in the array'' only applies to the trailing '\0'. Consequently, GCC at least warns: % avr-gcc -Wall -S foo.c foo.c:1: warning: initializer-string for array of chars is too long whereis it compiles char t[1] = "T"; without a complaint (to the same assembler code, of cause).
The standard allows the compiler to generate a warning for anything it likes. "Warning: there may be undetected errors in your program." "Warning: it's Friday, you'd better leave early to beat the traffic." But the construct must compile. As it apparently does.
My preference would be a warning in both cases (i.e., any time the initializer, including terminator, doesn't fit), especially with -Wall specified. But lint finds them for me, so I'm happy enough.
Regards, -=Dave _________________________________________________________________Is your PC infected? Get a FREE online computer virus scan from McAfee® Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
[Prev in Thread] | Current Thread | [Next in Thread] |