Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #394279

Re: type of decimal constants in msvc

Path csiph.com!eternal-september.org!feeder.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 Tue, 02 Sep 2025 13:46:26 -0700
Organization None to speak of
Lines 56
Message-ID <87jz2gbn19.fsf@example.invalid> (permalink)
References <1097ivh$ntii$1@dont-email.me>
MIME-Version 1.0
Content-Type text/plain
Injection-Date Tue, 02 Sep 2025 20:46:27 +0000 (UTC)
Injection-Info dont-email.me; posting-host="4c74183660f6bf6ea5f439f82abdc8bf"; logging-data="802169"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Fuyu2CBqiWuM2u7VaEnnX"
User-Agent Gnus/5.13 (Gnus v5.13)
Cancel-Lock sha1:5NsQRkd0kfFVGKsET3Brn1CyLsc= sha1:K/Uvs35WYJUFbMzIbZ+H+voRmKg=
Xref csiph.com comp.lang.c:394279

Show key headers only | View raw


Thiago Adams <thiago.adams@gmail.com> writes:
> 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.
>
> I was expecting "signed long long" (the next signed type) but MSVC
> instead uses unsigned long (that is 32 bits)
>
>
> #define is_type(T, E) _Generic(E, T : 1 , default:0 )
>
> static_assert(is_type(unsigned long, 2147483648));
>
> int main(){}
>
> https://godbolt.org/z/EqKWroecj
>
>
> The the standard says
> "The type of an integer constant is the first of the
> corresponding list in which its value can be represented."
>
> No suffix: The potential types, in order, are int, long int, and long
> long int.

Yes, that appears to be a bug.

I tried an example myself with Visual Studio 2022.  By default, it gives
2147483648 a type of unsigned long.

The default configuration is "/std:c17".  I thought it might be an
"extension" that I can disable with "/Za", but astonishingly that
produces a fatal error:

error D8016: '/Za' and '/std:c17' command-line options are incompatible

*Maybe* there's some combination of options that will persuade it to
behave correctly.

> So I think when "cloning" MSVC I need to not follow the standard.

I suppose, but it depends on why you want to clone MSVC and whether you
need to replicate its bugs.

I don't know whether this bug has been reported to Microsoft.  If not,
it should be.

> In GCC the type is long (that is 64 bits)
>
> https://godbolt.org/z/eTKE19r8K

On targets with 32-bit long, it should be long long.

-- 
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

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