Sujet : Re: What is your opinion about unsigned int u = -2 ?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 04. Aug 2024, 00:46:50
Autres entêtes
Organisation : None to speak of
Message-ID : <87jzgxdv9x.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Gnus/5.13 (Gnus v5.13)
Thiago Adams <
thiago.adams@gmail.com> writes:
More samples..
max uint64 + 1 is signed 128 bits in gcc and unsigned long long in clang
>
#ifdef __clang__
static_assert(TYPE_IS(9223372036854775808, unsigned long long ));
#else
static_assert(TYPE_IS(9223372036854775808, __int128));
#endif
>
https://godbolt.org/z/hveY44ov4
9223372036854775808 is 2**63, or INT64_MAX-1, not UINT64_MAX-1.
I suggest not doing *anything* that relies on the value of any decimal
constant greater than 2**63-1, unless you absolutely have to. (Since
you're working on a C23 transpiler, the latter probably does apply to
you.) 9223372036854775808 has no type unless there is some (possibly
extended) integer type wider than 64 bits, which is not the case for
either gcc or clang. Both compilers have made different decisions (and
I personally don't agree with either of them).
Incidentally, both gcc and clang reject 9223372036854775808 with a fatal
error with "-std=c23 -pedantic-errors".
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */