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/17/2003 16:34:47
> However the other related question remains: What does the C standard
> say is default implied type of a string literal when used as an
> initializer for a pointer type (as opposed to the array type above)?
You answered this yourself:
> If I understand correctly the only thing you said with respect to
> this question was:
>> A string literal forms an array of static storage duration with
>> elements of type char or wchar_t. const isn't mentioned in the
>> section on string literals at all.
There you are: its type is "array of char" or "array of wchar_t",
depending on whether or not it's a wide string literal.
> However this would mean that ISO/IEC 9899:1990 does not agree with
> GCC in practice (i.e. by default and then -fwritable-strings is not
> used)
By default? No, only when -Wwrite-strings is used. Yes, this means
that gcc -Wwrite-strings does not conform to the standard; neither does
any invocation of gcc without -ansi -pedantic (and possibly not even
that).
> and it would also mean that these three examples are not identical
> w.r.t. the "const" qualifiers
> { { char *foo;
> char *foo = "string"; char *foo; bar(char *tmp)
> } foo = "string"; {
> } foo = tmp;
> }
> {
> bar("string");
> }
They are identical with respect to const. Without -Wwrite-strings,
they all are fine; with -Wwrite-strings, each one discards a const
(which may or may not provoke a warning depending on other options).
> (You can implicitly, and in a non-portable way, get the address of a
> string literal used as an intializer IFF your compiler uses shared
> addresses for identical string literals. :-)
If you mean "initializer for char *", it's an expression like any other
expression (in this regard); if you mean "initializer for char []", no,
the double-quoted string does not have storage of its own - only the
array it initializes has storage. (I'm not sure whether it technically
is included in the term `string literal'.)
/~\ 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