c语言类型探索:unsigned long
0x00 缘起
目前在做mib相关的工作,oid节点的类型是counter64,支持私有mib的类型使用的是unsigned long,在考虑是不是够用,组内给出的结论是我们的平台上unsigned long和unsigned long long是相同位宽,即都为8字节。感觉自己基本功不扎实,故才有了这次探索
0x01 测试
事实胜于雄辩,我还是在设备上做下测试吧。结果显示的却是如此,unsigned long和unsigned long long是相同位宽,即都为8字节。
printf("unsigned long size = %ld\n", sizeof(unsigned long);
printf("unsigned long size = %ld\n", sizeof(unsigned long long);
0x02 查看规范
§5.2.4.2.1节给出了相关范围说明。
5.2.4.2.1 Sizes of integer types <limits.h>
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
exp