Hi,
On Tue, 4 Jul 2017, Michael Matz wrote:
> Ugh, you're right. Indeed the standard doesn't mandate a const char[]
> type for string literals (I was confused because it does say that
> modification of string literals is undefined, i.e. that's an extension).
> Let me work on this a bit.
Actually, not much need for work. I've checked GCC sources and, even
though it wonders in a comment if it's a good idea to change expression
types with warning flags, it indeed does so; so if for nothing else than
compatibility I've reverted the patch.
The hack in the current patch for _Generic (to regard string literals as
const char* always) isn't needed. GCC indeed differs in behaviour
depending on the warning flag, also in _Generic:
-----------------------
extern int printf(const char *,...);
int main()
{
const char *msg;
msg = _Generic("foo", const char *:"const char*", char*:"char *",
default:"something else");
printf ("type \"foo\" = %s\n", msg);
return 0;
}
-----------------------
% gcc-6 -Wwrite-strings x.c && ./a.out
type "foo" = const char*
% gcc-6 -Wno-write-strings x.c && ./a.out
type "foo" = char*
So, thanks for checking after me ;)
Ciao,
Michael.
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel