2

I would expect -2147483648 to be able to fit into 4 bytes because it is represented using 2's complement.

Am I missing something?

INT MIN: -2147483648
INT MAX: 2147483647
sizeof -2147483647: 4 
sizeof 2147483647: 4 
sizeof -2147483648: 8
sizeof 2147483648: 8
stefanhorne
  • 1,619
  • 3
  • 16
  • 23

1 Answers1

6

-2147483648 is 2147483648, a long number on your platform (because it's a decimal* greater than INT_MAX that fits in a long), negated. Numbers in C (and the C preprocessor) are parsed separately from the - unary operator. That is why e.g., the glibc implementation of the standard C library implements the INT_MIN macro as (-INT_MAX - 1).


*The rules determining what type to use for an integer literal with or without a suffix differ depending on the radix of the literal.

Petr Skocik
  • 58,047
  • 6
  • 95
  • 142