Subject: Re: toolchain/22118: make won't compile with -Wcast-qual -Wstrict-prototypes and more
To: NetBSD Toolchain Technical Discussion List <tech-toolchain@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-toolchain
Date: 07/16/2003 20:42:34
>>> Note also that there is no distinction in Standard C (though there
>>> seems to be in GCC's implementation) between a definition in the
>>> form "char foo[]" and a definition in the form "char *foo".
>> This is true when - and ONLY when - foo is a formal parameter to a
>> function.
> No, not only.... See K&R 2nd ed. page 99:
> In evaluating a[i], C converts it to *(a+i) immediately; the two
> forms are equivalent.
That is talking about the definition of the x[y] operator, which has
nothing to do with declarations, even declarations that use textually
similar syntax. (Related to this is the way an array is auto-converted
into a pointer to its [0] element when it appears in an rvalue context;
again, this affects expressions, not declarations.)
Look, if you think char foo[]; and char *foo; are equivalent
declarations for "foo is a pointer to char", try compiling these. Use
any compiler you care to. Heck, strip the ANSIisms and use pcc even.
int bar(void); int bar(void);
void blee(char); void blee(char);
int bar(void) int bar(void)
{ {
char foo[]; char *foo;
char c = 0; char c = 0;
foo = &c; foo = &c;
blee(*foo); blee(*foo);
} }
>> I don't know where you got this delusion that all read-only storage
>> must have a const-qualified type, but it doesn't agree with any
>> other reference I've ever found.
> I don't know which references you've relied upon, but read-only
> storage really must be const-qualified in order to make -Wconst-qual
> warnings be of any use whatsoever.
(a) Even if that were true, it's a gccism with little bearing on C.
(b) It's not true; there are people to whom -Wcast-qual (which is what
I assume you meant when you wrote -Wconst-qual) is of use despite the
presence of read-only storage that's not const-qualified. (Maybe it's
of no use _to you_; fine, nobody's making your code use it.)
> If you don't like these warnings then turn them off.
That's what I do. You don't like the way I do so; so be it. That
doesn't bother me - my own estimation of my code counts more to me than
yours, especially as you have never elucidated why it bothers you more
to turn them off at individual points in the code rather than
per-compilation-unit. (After all, turning them off with the
gcc-specific command-line options you keep recommending is even less
portable than my deconst().)
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B