当前位置: 动力学知识库 > 问答 > 编程问答 >

c - Long min limit in Visual Studio

问题描述:

Why does Visual Studio treats the constant -2147483648 (0x80000000) as unsigned?

From what I know this value is still within min limit for long.

Example, if you compile the following:

long a = -2147483648

The compiler will issue the following warning:

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

网友答案:

It's because the decimal constant here is not -2147483648, it's 2147483648 with the unary - operator applied to it. In C, numeric constants don't include signs.

2147483648 is out of range for long on your implementation, so under the C89 rules this has type unsigned long. Under the rules introduced in C99, it would instead have type long long.

To change this code to produce the value -2147483648 with type long, you can use:

long l = -2147483647 - 1;
网友答案:

Thats because maximum signed long could be 7FFFFFFF = 0111 1111 1111 1111 1111 1111 1111 1111.

分享给朋友:
您可能感兴趣的文章:
随机阅读: