Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.c > #395854

Re: type of decimal constants in msvc

Path csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: type of decimal constants in msvc
Date Fri, 19 Dec 2025 04:15:46 -0800
Organization None to speak of
Lines 65
Message-ID <875xa2u0p9.fsf@example.invalid> (permalink)
References <1097ivh$ntii$1@dont-email.me> <10i3dpt$14ajr$1@dont-email.me>
MIME-Version 1.0
Content-Type text/plain
Injection-Date Fri, 19 Dec 2025 12:15:47 +0000 (UTC)
Injection-Info dont-email.me; posting-host="ecbd26759f62ea1c20779b1a07dca9be"; logging-data="1195566"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18pjK/lbmulESSkPWuX28Wm"
User-Agent Gnus/5.13 (Gnus v5.13)
Cancel-Lock sha1:m5H2XgFAOLzyCiz2+S37HQPxsr4= sha1:XRJHkFN5ppJwxdPizNgconbTHxM=
Xref csiph.com comp.lang.c:395854

Show key headers only | View raw


Thiago Adams <thiago.adams@gmail.com> writes:
> Em 02/09/2025 17:10, Thiago Adams escreveu:
>> The type used by MSVC compiler seems not follow the C standard.
>> I choose the number 2147483648 that is the next number after max signed i32.
>
> For some reason GCC and clang have a warning (integer literal is too
> large to be represented in a signed integer type) only for decimal
> form.
>
> We have a warning for 18408377700990114895 but not for the same number
> written as hex 0xff77b1fcbebcdc4f.

Yes.

gcc's warning for 18408377700990114895 (which is slightly smaller
than 2**64) is "integer constant is so large that it is unsigned".
This is *incorrect* (and I think it's been reported as a bug), but
the incorrect wording of the warning is not a conformance issue.

(I'm assuming long long is 64 bits.  It can be wider, at least
theoretically.)

In C99 and later, an unsuffixed decimal constant is always of some
signed type, the smallest of int, long, and long long in which it
fits -- or of an extended integer type, but gcc doesn't have those.
Since 18408377700990114895 exceeds LLONG_MAX, it has no type, and
is a constraint violation. (In C90, the list was int, long, unsigned
long, which is the source of the wording of the warning message.)

An unsuffixed hex constant can be of type int, unsigned int, long
int, unsigned long int, long long int, or unsigned long long int
(or an extended integer type).  Since 0xff77b1fcbebcdc4f is greater
than LLONG_MAX and less than (or equal to) ULLONG_MAX, it's of type
unsigned long long int, and no diagostic is needed.

[...]

> But I don't think hex is especial in this case.

It is.

> unsigned long long u[] = {18408377700990114895 , 0xff77b1fcbebcdc4f};
>
> I think a suffix ULL maybe useful in this case.

This:

unsigned long long u[] = {18408377700990114895ULL, 0xff77b1fcbebcdc4fULL};

is valid.  The ULL suffix on the hex constant isn't strictly
necessary, but it certainly doesn't hurt.  (If unsigned long long is,
say, 128 bits and long is 64 bits, an unsuffixed 18408377700990114895
will be of type long long, and an unsuffixed 0xff77b1fcbebcdc4f
will be of type unsigned long, both of which will be implicitly
converted to unsigned long long.)

For that matter, just a "U" suffix would suffice.  A decimal constant
with a "U" suffix is of type unsigned int, unsigned long int, or
unsigned long long int.

See N1570 6.4.4.1 or N3220 6.4.4.2.

-- 
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 | NextPrevious in thread | Next in thread | Find similar


Thread

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

csiph-web