c - C中的 'short'数据类型是什么?

标签 c short

在下面的函数中:

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

该函数正在获取一个 short 类型。 我在网上做了一些搜索,但只找到了 short int。 当一个函数得到一个短类型时,这意味着什么? 它是什么数据类型?

最佳答案

shortshort int 的缩写。它们是同义词。 shortshort intsigned shortsigned short int 都是相同的数据类型。 short 中究竟有多少位取决于编译器和系统,但必须有 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 .

更多来自 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.

编辑:

LP64下(所有64位非Windows操作系统):char为8位,short为16位,int为32位,long为64位,long long可能为128位。

Windows 保留 LLP64:char 为 8 位,short 为 16 位,int 为 32 位,long 为 32 位,long long 为 64 位。

关于c - C中的 'short'数据类型是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15505828/

相关文章:

c - unsigned short 与 unsigned int - 有时它们的范围相同?

c - 将 MAC 地址解析为三个 16 位短整型数组

c++ - Arduino : Can import library in ino, 但不在 C++ 中

c - 空检查前取消引用

c - C语言中如何更新数组的值

c - 短与 Int Gcc

c 内联汇编字符数组转短

Java,用所有 16 位打印一个短的二进制文件

c++ - 返回与。指针

C 结构体赋值可以使用大括号语法吗?