Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: type of decimal constants in msvc Date: Mon, 15 Dec 2025 14:14:43 -0800 Organization: None to speak of Lines: 65 Message-ID: <87tsxrtmss.fsf@example.invalid> References: <1097ivh$ntii$1@dont-email.me> <87jz2gbn19.fsf@example.invalid> <86345bvifp.fsf@linuxsc.com> <10hpf1f$21ulj$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Mon, 15 Dec 2025 22:14:47 +0000 (UTC) Injection-Info: dont-email.me; posting-host="1c4637fb3b5663b94c1d68a6155d6aa3"; logging-data="2355630"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Qs0bqRYyl1pv6YK6m/2Lf" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:RzrAsg/3S2x4E32nhmBiBJhuz1o= sha1:ChFFy7QttRB2RJ0H+BEu3juZ7Y8= Xref: csiph.com comp.lang.c:395825 Thiago Adams writes: [...] > Today, when the number is not represented in a signed 64 bits, in > theory it should use 128 signed, but it uses 64 unsigned instead and > we have a warning. In C99 and later, an unsuffixed integer constant is *never* of unsigned type. > For instance: > > 9223372036854775808 That's 2**63, likely equal to LLONG_MAX+1. > warning: integer literal is too large to be represented in a signed > integer type, interpreting as unsigned [-Wimplicitly-unsigned-literal] > > What is interesting that C code is not portable. (nothing new, just saying) The error message is incorrect, a bug that's been reported against gcc : https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96788 But I think that error message is from clang (gcc's message refers to "integer constant", clang's to "integer literal"). The type of an unsuffixed integer constant is the first of (int, long int, long long int) in which its value can be represented. If it exceeds LLONG_MAX, it *may* be of an extended integer type; neither gcc nor clang supports extended integer types. Failing that, "the integer constant has no type", which violates a constraint: "Each constant shall have a type and the value of a constant shall be in the range of representable values for its type." With 64-bit gcc, 9223372036854775808 is of type __int128 -- which (a) is not an unsigned type, as stated by the incorrect warning message, and (b) is *not* an extended integer type. (gcc does produce a diagnostic, which is all that's required for a constraint violation, but it's certainly a bug.) With 64-bit clang, 9223372036854775808 is of type unsigned long long, which is incorrect but at least consistent with the warning message. #include int main(void) { printf("9223372036854775808 is of type %s\n", _Generic(9223372036854775808, int: "int", unsigned int: "unsigned int", long: "long", unsigned long: "unsigned long", long long: "long long", unsigned long long: "unsigned long long", #ifdef __GNUC__ __int128: "__int128", unsigned __int128: "unsigned __int128", #endif default: "" )); } -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */