c语言类型探索:unsigned long

本文讲述了作者在进行MIB工作时,对C语言中unsigned long类型的位宽产生疑问,通过测试和查阅规范发现,在其工作平台上unsigned long和unsigned long long都是8字节。通过man limits.h进一步确认了这一情况,并引发了对64位编程模型的思考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
expression that is an object of the corresponding type converted according to the integer promoti
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值