In the following function:
void AddWordData(FILE* dataFile, short word, int* dc)
{
fprintf(dataFile, "%06o\n", word);
++(*dc);
}
the function is getting a short type. I did some search in the web but found only short int. what does it mean when a function is getting a short type? what datatype is it?
short
is short for short int
. They are synonymous. short
, short int
, signed short
, and signed short int
are all the same data-type. Exactly how many bits are in a short
depends on the compiler and the system, but it is required to have at least 16 bits:
Any compiler conforming to the Standard must also respect the following limits with respect to the range of values any particular type may accept. Note that these are lower limits: an implementation is free to exceed any or all of these. Note also that the minimum range for a char is dependent on whether or not a char is considered to be signed or unsigned. ... short int: -32767 to +32767 .
More from Wikipedia:
The actual size of integer types varies by implementation. The only guarantee is that the long long is not smaller than long, which is not smaller than int, which is not smaller than short. Also, int should be the integer type that the target processor is most efficient working with. This allows great flexibility: for example, all types can be 64-bit. However, only several different integer width schemes (data models) are popular and since data model defines how different programs communicate, a uniform data model is used within a given operating system application interface.[3]
In practice it should be noted that char is usually 8 bits in size, short is usually 16 bits in size and long is usually 32 bits in size (likewise unsigned char, unsigned short and unsigned long). For example this holds true for platforms as diverse as 1990s Sun0S 4 Unix, Microsoft MSDOS, modern Linux, and Microchip MCC18 for embedded 8-bit PIC microcontrollers.
Edit:
Under LP64 (all 64-bit non-Windows operation system): char is 8 bits, short is 16 bits, int is 32 bits, long is 64 bits, and long long may be 128 bits.
Windows keeps LLP64: char is 8 bits, short is 16 bits, int is 32 bits, long is 32 bits, and long long is 64 bits.