Ben said:
CBFalconer said:
Harald van D?k wrote:
... snip ...
Why do you want to use -ansi if you're going to include another
option that deliberately makes the compiler fail to conform to any
standard?
And what do you consider does that? A warning does not prevent
compilation.
Consider the following:
void f(const char (*cp)[4]);
void g(void) { f(&"abc"); } /* modified cf */
It requires a diagnostic which -Wwrite-strings suppresses.
I don't see that. Are you confused about the meaning of
-Wwrite-strings?
He's not.
The type of "abc" according to the standard is char[4], not const char[4].
And the type of &"abc" is char(*)[4], not const char(*)[4]. There is no
implicit conversion from char(*)[4] to const char(*)[4], so Ben's code
violates a constraint. And if you make the code
void f(char (*cp)[4]);
void g(void) { f(&"abc"); }
then the code is correct, no constraint is violated, and gcc will accept
the code, but it will emit a very misleading diagnostic strongly
suggesting the code is incorrect.
Admittedly a stretch, but you can even get gcc to reject valid code with
your options:
void f(void) { *"" = 0; }
This is allowed in a strictly conforming program as long as f is never
called, yet gcc will issue a hard error for it with your options. At least
you won't find this one outside of a conformance test though.