Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
int a = -2147483648;
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Army1987, post: 2961580"] I guess you have 32-bit ints with 2's complement. The C99 rationale (6.4.4.4.)says "Notwithstanding the general rule that literal constants are non-negative, 3..." where the footnote is "3 Note that -4 is an expression: unary minus with operand 4.". INT_MAX is 0x7FFFFFFF, so a decimal constant of 0x80000000 doesn't fit in a signed int, and if INT_MAX == LONG_MAX, not even in a signed long. In C89 this would cause it to have unsigned type. Negating it yields UINT_MAX + 1 - 0x80000000 which is 0x80000000, which doesn't fit in a signed int. Try using: long a = -2147483647 - 1, for example MSVC #define's INT_MIN this way (but with parentheses around it). Note that in C89 no type is *required* to be able to hold that value, so the program won't be portable everywhere. But using long will make it portable even on systems with 16-bit int, provided they use two's complement. (Or INT_MIN if you mean that. If you have C99 maybe you want to use INT32_MIN and declare a as an int32_t, these are defined in <stdint.h>.) [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
int a = -2147483648;
Top