[SOLVED] short keyword

WBahn

Joined Mar 31, 2012
30,082
These are the short and long qualifier rules.

long long is not smaller than long, which is not smaller than int, which is not smaller than short. Very clear, right.
In most compilers at least one of those assertions would be false.

I recommend revising that to:

long long is not necessarily smaller than long, which is not necessarily smaller than int, which is not necessarily smaller than short. Very clear, right.
 

nsaspook

Joined Aug 27, 2009
13,315
Sure, the standard is as clear as mud.

http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf

6.2.5 Types

There are five standard signed integer types, designated as signed char, short int, int, long int, and long long int. (These and other types may be designated in several additional ways, as described in 6.7.2.) There may also be implementation-defined extended signed integer types. 28) The standard and extended signed integer types are collectively called signed integer types. 29)

6.3 Conversions

6.3.1.1 Boolean, characters, and integers
1
Every integer type has an integer conversion rank defined as follows: — No two signed integer types shall have the same rank, even if they have the same representation. —
The rank of a signed integer type shall be greater than the rank of any signed integer type with less precision.

Every integer type has an integer conversion rank defined as follows: — No two signed integer types shall have the same rank, even if they have the same representation. — The rank of a signed integer type shall be greater than the rank of any signed integer type with less precision. —

The rank of long long int shall be greater than the rank of long int, which shall be greater than the rank of int, which shall be greater than the rank of short int, which shall be greater than the rank of signed char.
 

Ian Rogers

Joined Dec 12, 2012
1,136
@Djsarakar

The confusion isn't the use of short but the use of int. If you ask anyone here how big an int is, there will be essay after essay.

An int is an integer number.. 2 bits though 64 bits and above. C was simpler back then. An 8 bit computer default int was 8 bits. A 16 bit default was 16 bits then 32bits.... So it was changed to long and short .. A short int for the 16 bit and a long int for 32 bits, then the long long int for 64 bits.

Other compilers use word and double word... ( simpler in my view ) but double is already taken in C..

so recap...
signed or unsigned char.
signed or unsigned short int.
signed or unsigned long int.
signed or unsigned long long int.

If you use just int and long, the compiler knows what you want...

I tend to include ctypes and use UINT8 / INT8 ~ UINT32 / INT32 as others have said..
 
Top