MSVC 版本 17.11.3 编译器中可能存在与整数文字类型相关的错误?

问题描述 投票:0回答:1

我在 Win10 64 位上使用 VS2022 和版本 17.11.3 编译器,下面是我的代码及其输出。 我的理解是,用十进制表示的没有后缀的整数字面量的类型是 int、long 和 long long 类型中第一个可以容纳该值的类型。 如果是这样的话,我相信 sizeof(2147483648) 的值应该是 8 而不是 4,如果我切换到 VS2022 附带的 clang 编译器,它确实是 8。 如果这是一个错误,是否值得尝试向 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";
}

输出:

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

sizeof(2147483647) = 4
sizeof(2147483648) = 4
c++ visual-studio
1个回答
0
投票

正如 3CxEZiVlQ 所说, 2147483648 是无符号整数

Visual Studio 最新版本是17.11.4。

sizeof(2147483648) 是 8。

所以您无需报告此问题。并更新您的 Visual Studio。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.