What about (1 << (8*sizeof(int)-2)) - 1 + (1 << (8*sizeof(int)-2))
.
This is the same as 2^(8*sizeof(int)-2) - 1 + 2^(8*sizeof(int)-2)
.
If sizeof(int) = 4 => 2^(8*4-2) - 1 + 2^(8*4-2) = 2^30 - 1 + 20^30 = (2^32)/2 - 1 [max signed int of 4 bytes]
.
You can't use 2*(1 << (8*sizeof(int)-2)) - 1
because it will overflow, but (1 << (8*sizeof(int)-2)) - 1 + (1 << (8*sizeof(int)-2))
works.