Your function always return 1 on machines with 32-bit int because
mask >> 31 will return 1 or ~0 depending on that compiler uses arithmetic or logical shift right, and apply
mask >> 31 makes it return 1. Also, you should print the result of the function instead of printing in the function and discard the result.
Also note that people often use
1 << 31 rather than
0x80 << 24. And you need
U suffix to make sure that it doesn't invoke undefined behavior due to overflow.
(int)((signed char)0x80) << 24 will be OK in case
CHAR_BIT == 8 but
0x80 << 24 won't, because 0x80 is a positive number in the range of
int, and shifting it 24 bits cause the number to overflow
#define NUM_BITS (sizeof(int)*CHAR_BIT)
int mask = (int)(0x01U << (NUM_BITS - 1));
return (mask >> (NUM_BITS - 1)) != 1;
But to be efficient, use
return ((~0) >> 1) == (~0);
instead. It'll work regardless of the signed type form because like I said in the other comment, vnp's solution won't work if the system uses sign-magnitude form.
Even better, define the function as macro or inline it.