目前在做mib相关的工作,oid节点的类型是counter64,支持私有mib的类型使用的是unsigned long,在考虑是不是够用,组内给出的结论是我们的平台上unsigned long和unsigned long long是相同位宽,即都为8字节。感觉自己基本功不扎实,故才有了这次探索
事实胜于雄辩,我还是在设备上做下测试吧。结果显示的却是如此,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);§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 expression that is an object of the corresponding type converted according to the integer promotions. Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign. ... — maximum value for an object of type long int LONG_MAX +2147483647 // 231 − 1 — maximum value for an object of type unsigned long int ULONG_MAX 4294967295 // 232 − 1 ...从这里看出是给出了相关的说明,但是没有给出具体是多少,就是说,不知道是多少。不过这里给出了线索,即limits.h。
man limits.h给出如下:
{ULONG_MAX} Maximum value of type unsigned long. Minimum Acceptable Value: 4 294 967 295可接受的最小值为4 294 967 295,我们是8字节宽度,比这个值大。至此水落石出,明白了其中的关系。
看似不经意的一个地方,考察着一个知识体系的理解,这个层次性的理解中,目前我们只知道结论,不清楚为什么是这样,留待以后再研究。
1,64位编程模型:为什么要使用LP64(一) 2. 上述原文出处