tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] _Generic or __builtin_choose_expr


From: uso ewin
Subject: Re: [Tinycc-devel] _Generic or __builtin_choose_expr
Date: Tue, 4 Jul 2017 18:04:53 +0200

On Tue, Jul 4, 2017 at 5:59 PM, uso ewin <address@hidden> wrote:
> Hi
>
> I've push a new version that use skip_or_save_block from mob:
> https://github.com/cosmo-ray/tcc/commits/mob
> I've let the patch that change ex1.c that I used as testing so you can
> see my ugly tests.
>
> On Tue, Jul 4, 2017 at 4:46 PM, Michael Matz <address@hidden> wrote:
>> 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 ;)
>>
>
> Well, I've just test
> 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;
> }
oops, I've just type a bad shortcut on google,
and apparently unexpectedly send the mail before finish typing... sorry

So it appear than gcc remove const from variable:
so
const int a;

i = _Generic(a, int: 10, const int: 20);
printf("%d\n", i);

will print 10...

But as your example show early with  -Wwrite-strings gcc let the const....


I've made some code that remove each const,
and change array to pointer on my branch,
but I'm not sure of the idea



reply via email to

[Prev in Thread] Current Thread [Next in Thread]