What is a "short" data type in C?

In the following function:

void AddWordData(FILE* dataFile, short word, int* dc) { fprintf(dataFile, "%06o\n", word); ++(*dc); } 

the function gets a short type. I did a search on the internet but found only a short int. what does this mean when a function gets a short type? what type of data?

+6
source share
1 answer

short not suitable for short int . They are synonyms. short , short int , signed short and signed short int are all the same data types. Exactly how many bits in short depends on the compiler and the system, but at least 16 bits are required:

Any compiler complying with the Standard must also comply with the following restrictions on the range of values ​​that any particular type can accept. Note that these are lower limits: an implementation may exceed any or all of them. Note also that the minimum range for char depends on whether char is considered signed or unsigned .... short int: -32767 to +32767.

More from Wikipedia :

The actual size of integer types is implementation dependent. The only guarantee is that long long is not less than long, which is no less than int, which is not less than short. In addition, int must be the integer type with which the target processor works most efficiently. This provides more flexibility: for example, all types can be 64-bit. However, only a few different integer width schemes (data models) are popular, and since the data model determines how different programs interact, a single data model is used within the application interface of the operating system. [3]

In practice, it should be noted that char usually has a size of 8 bits, short, usually 16 bits, and the length is usually 32 bits (also unsigned char, unsigned short and unsigned long). For example, this is true for platforms as diverse as the Sun0S 4 Unix, Microsoft MSDOS, modern Linux, and Microchip MCC18 for embedded 8-bit PIC microcontrollers in the 1990s.

+14
source

All Articles