Search code examples
c++visual-studio

Possible bug in MSVC Version 17.11.3 compiler pertaining to integer literal types?


I'm using VS2022 with the version 17.11.3 compiler on Win10 64-bit and my code is below followed by its output. My understanding is that the type of an integer literal expressed in decimal with no suffix is the first of types int, long, and long long that can accommodate the value. If that is the case, I believe the value of sizeof(2147483648) should be 8 and not 4, it and is indeed 8 if I switch to the clang compiler that comes with VS2022. If this is a bug, is it worth trying to report it to Microsoft?

#include <climits>
#include <iostream>
using namespace std;

int main()
{
    cout << "LONG_MAX = " << LONG_MAX << "\n";
    cout << "sizeof(long) = " << sizeof(long) << "\n";
    cout << "LLONG_MAX = " << LLONG_MAX << "\n";
    cout << "sizeof(long long) = " << sizeof(long long) << "\n";
    cout << "\n";
    cout << "sizeof(2147483647) = " << sizeof(2147483647) << "\n";
    cout << "sizeof(2147483648) = " << sizeof(2147483648) << "\n";
}

Output:

LONG_MAX = 2147483647
sizeof(long) = 4
LLONG_MAX = 9223372036854775807
sizeof(long long) = 8

sizeof(2147483647) = 4
sizeof(2147483648) = 4

Solution

  • Visual Studio latest version is 17.11.4.

    sizeof(2147483648) is 8.

    So you don't need to report this issue. And update your Visual Studio. enter image description here

    enter image description here