Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: What is your opinion about unsigned int u = -2 ? Date: Sat, 03 Aug 2024 16:46:50 -0700 Organization: None to speak of Lines: 28 Message-ID: <87jzgxdv9x.fsf@nosuchdomain.example.com> References: <87bk2cecan.fsf@bsb.me.uk> <87r0b6g3qx.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Sun, 04 Aug 2024 01:46:51 +0200 (CEST) Injection-Info: dont-email.me; posting-host="d07bdb3c66a7f25ead61bbbbc164c6d5"; logging-data="3865857"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192oPAHcub6ROvN5Gar6gwi" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:chIol1dPqCntYsVeufBXIwkx8KQ= sha1:hXKTxMUZErGHrMp0lm8FJF0QZ2M= Bytes: 2411 Thiago Adams 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.com void Void(void) { Void(); } /* The recursive call of the void */