Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #395825
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: type of decimal constants in msvc |
| Date | 2025-12-15 14:14 -0800 |
| Organization | None to speak of |
| Message-ID | <87tsxrtmss.fsf@example.invalid> (permalink) |
| References | <1097ivh$ntii$1@dont-email.me> <87jz2gbn19.fsf@example.invalid> <86345bvifp.fsf@linuxsc.com> <10hpf1f$21ulj$1@dont-email.me> |
Thiago Adams <thiago.adams@gmail.com> 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 <stdio.h>
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: "<unknown>"
));
}
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
type of decimal constants in msvc Thiago Adams <thiago.adams@gmail.com> - 2025-09-02 17:10 -0300
Re: type of decimal constants in msvc Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-09-02 13:46 -0700
Re: type of decimal constants in msvc Thiago Adams <thiago.adams@gmail.com> - 2025-09-02 20:39 -0300
Re: type of decimal constants in msvc Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-12-15 08:06 -0800
Re: type of decimal constants in msvc Thiago Adams <thiago.adams@gmail.com> - 2025-12-15 14:03 -0300
Re: type of decimal constants in msvc Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-12-15 14:14 -0800
Re: type of decimal constants in msvc Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-09-03 06:42 +0000
Re: type of decimal constants in msvc BGB <cr88192@gmail.com> - 2025-09-03 10:59 -0500
Re: type of decimal constants in msvc Michael S <already5chosen@yahoo.com> - 2025-09-04 15:21 +0300
Re: type of decimal constants in msvc Thiago Adams <thiago.adams@gmail.com> - 2025-09-03 16:04 -0300
Re: type of decimal constants in msvc Thiago Adams <thiago.adams@gmail.com> - 2025-12-19 08:43 -0300
Re: type of decimal constants in msvc Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-12-19 04:15 -0800
Re: type of decimal constants in msvc Thiago Adams <thiago.adams@gmail.com> - 2025-12-19 09:49 -0300
Re: type of decimal constants in msvc Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-12-19 12:26 -0800
Re: type of decimal constants in msvc Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-12-22 05:05 -0800
Re: type of decimal constants in msvc Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2025-12-22 12:01 -0800
Re: type of decimal constants in msvc Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-01 18:32 -0800
Re: type of decimal constants in msvc Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-01 19:22 -0800
csiph-web