Deutsch   English   Français   Italiano  
<v8mmi2$3rdcj$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Thiago Adams <thiago.adams@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: What is your opinion about unsigned int u = -2 ?
Date: Sat, 3 Aug 2024 22:46:42 -0300
Organization: A noiseless patient Spider
Lines: 93
Message-ID: <v8mmi2$3rdcj$1@dont-email.me>
References: <v8dfo9$1k7cg$1@dont-email.me>
 <pan$d2c8a$8c54ac9f$29a202e0$12c6ce86@invalid.invalid>
 <87bk2cecan.fsf@bsb.me.uk> <v8inds$2qpqh$1@dont-email.me>
 <v8iqnr$7l3c$1@news.xmission.com> <v8irje$2rolg$1@dont-email.me>
 <87r0b6g3qx.fsf@nosuchdomain.example.com> <v8jbj5$2us0r$4@dont-email.me>
 <v8jvln$33atp$1@dont-email.me> <v8k055$33fcl$1@dont-email.me>
 <87cymqfl3m.fsf@nosuchdomain.example.com> <v8k2ck$33nca$2@dont-email.me>
 <874j82fiew.fsf@nosuchdomain.example.com> <v8l887$3edtr$1@dont-email.me>
 <87v80hdwyx.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 04 Aug 2024 03:46:42 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="6fc28f04c078ea4656b78eef07069d0e";
	logging-data="4044179"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+tIwGO8jJB4ZthUIk/nh+99jAfHG95OOg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:8pCC0RosyX1EonEoZ/iXuI1qjjA=
In-Reply-To: <87v80hdwyx.fsf@nosuchdomain.example.com>
Content-Language: en-GB
Bytes: 5740

Em 8/3/2024 8:10 PM, Keith Thompson escreveu:
> You must have done something odd when posting your followup.  The
> attributions are messed up.
> 
> Thiago Adams <thiago.adams@gmail.com> writes:
>> -------- Mensagem encaminhada --------
>> Assunto: Re: What is your opinion about unsigned int u = -2 ?
>> Data: Fri, 02 Aug 2024 19:29:27 -0700
>> De: Keith Thompson <Keith.S.Thompson+u@gmail.com>
>> Organização: None to speak of
>> Grupos de notícias: comp.lang.c
>> Referências: <v8dfo9$1k7cg$1@dont-email.me>
>> <pan$d2c8a$8c54ac9f$29a202e0$12c6ce86@invalid.invalid>
>> <87bk2cecan.fsf@bsb.me.uk> <v8inds$2qpqh$1@dont-email.me>
>> <v8iqnr$7l3c$1@news.xmission.com> <v8irje$2rolg$1@dont-email.me>
>> <87r0b6g3qx.fsf@nosuchdomain.example.com>
>> <v8jbj5$2us0r$4@dont-email.me> <v8jvln$33atp$1@dont-email.me>
>> <v8k055$33fcl$1@dont-email.me>
>> <87cymqfl3m.fsf@nosuchdomain.example.com>
>> <v8k2ck$33nca$2@dont-email.me>
>>
>> Thiago Adams <thiago.adams@gmail.com> writes:
>>> Em 8/2/2024 10:31 PM, Keith Thompson escreveu:
>>>> Thiago Adams <thiago.adams@gmail.com> writes:
>>>> [...]
>>>>> It is interesting to compare constexpr with the existing constant
>>>>> expression in C that works with integers.Compilers extend to work with
>>>>> unsigned long long.
>>>>> constexpr works with the sizes as defined , for instance char.
>>>> I'm not sure what you mean by "Compilers extend to work with
>>>> unsigned long long.".
>>>
>>> enum {C = 18446744073709551615 -1 };
>>> //        ~~~~~~~~~~~~~~~~~~~~
>>> //        ^ warning: integer constant is so large that it is unsigned
>>>
>>> https://godbolt.org/z/K7hzczETP
>>
>> Since 18446744073709551615 is 2**64-1, it's outside the range of any
>> signed integer type in typical implementations.  Since unsuffixed
>> integer constants are of some signed type (since C99), that constant is
>> likely to cause problems.  You could write 18446744073709551615ull.
>>
>> That's a rather odd warning.  In C90, an unsuffixed integer constant's
>> type was the first of (int, long int, unsigned long int) in which its
>> value would fit.  In C99 and later, an unsuffixed integer constant is of
>> type int, long int, or long long int, *never* of any unsigned type.
>> Since 18446744073709551615 exceeds ULLONG_MAX (assuming 64 bits),
>> apparently gcc treats it as having an unsigned type as an extension.
>>
> KT> (My quick experiment indicates that, at least on my system,
> KT> 18446744073709551615 is of type __int128 and, bizarrely,
> KT> 18446744073709551616 is of type int with the value 0.  This seems
> KT> like a bug.)
> 
> [...]
> 
> TA> I checked and 18446744073709551615 is not unsigned long long
> TA>
> TA> static_assert(TYPE_IS(18446744073709551615, unsigned long long));
> TA>
> TA> https://godbolt.org/z/vnzWWxvjr
> 
> Right.  As I said, gcc gives it type __int128.  This is to be expected
> if __int128 is an *extended integer type*, but in fact it's an
> extension, and gcc's behavior appears reasonable on that basis.  In the
> absence of integer types wider than 64 bits, 18446744073709551615
> (2**64-1) has no type.  If you need that particular value in your code,
> I suggest finding a different way to express it.  18446744073709551615u
> or 0xffffffffffffffff are possibilities; so is ULLONG_MAX if long long
> is 64 bits and that expresses your intent more clearly.
> 
>>> "In C99 and later, an unsuffixed integer constant is of
>>> type int, long int, or long long int, *never* of any unsigned type."
>>
>> I think this should be reviewed before they constexpr was added in C.
> 
> That's not going to happen, and I'm not sure why it should.
> 
>> I am fixing my constant expression evaluation in cake and I will share
>> the code of "old" constant expressions and new constexpr. So constexpr
>> does not have restriction on signed types only.
> 
> constexpr has never been restricted to signed types.  Unsuffixed integer
> constants are.  That's why there are suffixed integer constants.
> 

Everything is becoming a little clear in my mind. (Some of my previous 
comments are wrong)
Thanks for helping clarify the concepts.