<small id='9Yei8'></small><noframes id='9Yei8'>

    <legend id='9Yei8'><style id='9Yei8'><dir id='9Yei8'><q id='9Yei8'></q></dir></style></legend>

  1. <i id='9Yei8'><tr id='9Yei8'><dt id='9Yei8'><q id='9Yei8'><span id='9Yei8'><b id='9Yei8'><form id='9Yei8'><ins id='9Yei8'></ins><ul id='9Yei8'></ul><sub id='9Yei8'></sub></form><legend id='9Yei8'></legend><bdo id='9Yei8'><pre id='9Yei8'><center id='9Yei8'></center></pre></bdo></b><th id='9Yei8'></th></span></q></dt></tr></i><div id='9Yei8'><tfoot id='9Yei8'></tfoot><dl id='9Yei8'><fieldset id='9Yei8'></fieldset></dl></div>
      • <bdo id='9Yei8'></bdo><ul id='9Yei8'></ul>
    1. <tfoot id='9Yei8'></tfoot>
    2. Visual Studio 2015 - 编译器警告(级别 2)C4146

      时间:2023-09-27

      <small id='cQDZQ'></small><noframes id='cQDZQ'>

        • <bdo id='cQDZQ'></bdo><ul id='cQDZQ'></ul>
                <legend id='cQDZQ'><style id='cQDZQ'><dir id='cQDZQ'><q id='cQDZQ'></q></dir></style></legend>
                  <tbody id='cQDZQ'></tbody>
                <tfoot id='cQDZQ'></tfoot>
              • <i id='cQDZQ'><tr id='cQDZQ'><dt id='cQDZQ'><q id='cQDZQ'><span id='cQDZQ'><b id='cQDZQ'><form id='cQDZQ'><ins id='cQDZQ'></ins><ul id='cQDZQ'></ul><sub id='cQDZQ'></sub></form><legend id='cQDZQ'></legend><bdo id='cQDZQ'><pre id='cQDZQ'><center id='cQDZQ'></center></pre></bdo></b><th id='cQDZQ'></th></span></q></dt></tr></i><div id='cQDZQ'><tfoot id='cQDZQ'></tfoot><dl id='cQDZQ'><fieldset id='cQDZQ'></fieldset></dl></div>
                本文介绍了Visual Studio 2015 - 编译器警告(级别 2)C4146的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我的代码中有以下行

                signed int test_case= -2147483648;
                

                产生错误:

                C4146 一元减运算符应用于无符号类型,结果仍然无符号

                C4146 unary minus operator applied to unsigned type, result still unsigned

                但这仍然是有符号整数类型的数据范围:

                but this is still with the data range of teh signed integer type:

                __int32 有符号、有符号 int、int –2,147,483,648 到 2,147,483,647

                __int32 signed, signed int, int –2,147,483,648 to 2,147,483,647

                奇怪的是将它分配为 signed long 给出了同样的错误,即

                The strange things is assigning it as signed long gives this same error, i.e.

                signed long test_case= -2147483648;
                

                以下更改编译正常:

                signed int test_case= -2147483647;
                
                signed int test_case= 2147483649;
                
                signed long test_case= -214748364800;
                

                • 有人在 Visual Studio 2015 编译器中看到过这个问题吗?
                • 它是如何定义数据类型的?
                • 如何检查范围?
                • 为什么它似乎忽略了已签名"分配?
                • 谢谢

                  推荐答案

                  由于它是一个编译器错误,这个答案是特定于 MSVC 的,它是错误的 从 iso C++ 的角度来看.有关正确和标准的答案,请参阅@Bathsheba 的答案.(我鼓励 OP 接受正确答案,而不是为未来的读者接受此答案).

                  Since it is a compiler bug, this answer is specific to MSVC and it is wrong from iso C++ perspective. For the correct and standard answer please see @Bathsheba answer. (I encourage the OP to accept the correct answer instead of this answer for future readers).

                  来自 MSDN:

                  计算数字 2147483648.因为它大于最大整数值 2147483647,2147483648 的类型不是int,但无符号整数.

                  The number 2147483648 is evaluated. Because it is greater than the maximum integer value of 2147483647, the type of 2147483648 is not int, but unsigned int.

                  换句话说,编译器会将 -2147483648 处理为 -2147483648 而不是 -2147483648.所以 2147483648 部分被认为是 unsigned int,因为它比 int 大.然后编译器应用导致此警告的 - 运算符.

                  In other words, the compiler will deal with -2147483648 as - and 2147483648 not as -2147483648. So the 2147483648 part is considered as unsigned int since it is bigger than int. and then the compiler applies the - operator which is leading to this warning.

                  解决方案:

                  auto test_case= -2147483648ll;
                  

                  这篇关于Visual Studio 2015 - 编译器警告(级别 2)C4146的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:MSbuild 错误:找不到 v140(平台工具集 = 'v140')的构建工具 下一篇:在 VC 2015 上使用带有字符串的宏失败

                相关文章

                1. <tfoot id='E37wF'></tfoot><legend id='E37wF'><style id='E37wF'><dir id='E37wF'><q id='E37wF'></q></dir></style></legend>

                    <bdo id='E37wF'></bdo><ul id='E37wF'></ul>

                2. <small id='E37wF'></small><noframes id='E37wF'>

                  <i id='E37wF'><tr id='E37wF'><dt id='E37wF'><q id='E37wF'><span id='E37wF'><b id='E37wF'><form id='E37wF'><ins id='E37wF'></ins><ul id='E37wF'></ul><sub id='E37wF'></sub></form><legend id='E37wF'></legend><bdo id='E37wF'><pre id='E37wF'><center id='E37wF'></center></pre></bdo></b><th id='E37wF'></th></span></q></dt></tr></i><div id='E37wF'><tfoot id='E37wF'></tfoot><dl id='E37wF'><fieldset id='E37wF'></fieldset></dl></div>