Can an int be unsigned by default like char and can someone provide these platform if it exists ?
I mean that char can be unsigned or signed depending on platforms.
Is the same thing applicable to int, long, short ?
Can an int be unsigned by default like char and can someone provide these platform if it exists ?
I mean that char can be unsigned or signed depending on platforms.
Is the same thing applicable to int, long, short ?
No, int is always signed. Unlike char, which may behave as a signed char or unsigned char depending on the platform, int is always a synonym for signed int, regardless of the platform, in both C and C++.
Reference: C99, 6.2.5.4:
There are five standard signed integer types, designated as
signed char,short int,int,long int, andlong long int.Reference: C++11, 3.9.1.2:
There are five standard signed integer types :
signed char,short int,int,long int, andlong long int.
char is peculiar: there are three flavors, signed char, unsigned char, and char. A plain char can be signed or unsigned, depending on the implementation, but in C++ it's a different type from the other two. All the other integer types have just two flavors, signed and unsigned; you can say unsigned int, signed int, and just plain int, but plain int is signed, and it's just a different name for signed int. In the C++ standard, that's clause 3.9.1, [basic.fundamental].
As per the C11 standard section "5.2.4.2.1 Sizes of integer types ":
The values given below shall be replaced by constant expressions suitable for use in #if preprocessing directives. Moreover, except for CHAR_BIT and MB_LEN_MAX, the following shall be replaced by expressions that have the same type as would an expression that is an object of the corresponding type converted according to the integer promotions. Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.
...........................
minimum value for an object of typeint
INT_MIN -32767
maximum value for an object of typeint
INT_MAX +32767
So, as you can see the limits of int have to be at least the ones specified (absolute values) with the same signs.