码迷,mamicode.com
首页 > 其他好文 > 详细

一个int类型究竟占多少个字节

时间:2014-07-25 19:05:41      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   os   strong   for   art   re   

一个int占多少个字节?

这个问题我们往往得到的答案是4.

可是int究竟占多少个字节,却跟你的机器环境有关.

bubuko.com,布布扣

As you can see, the typical data type sizes match the ILP32LL model, which is what most compilers adhere to on 32-bit platforms. The LP64 model is the de facto standard for compilers that generate code for 64-bit platforms.

近期在一本有关代码审计的书上看到如上解释.这里非常好的解释了int究竟应该占多少个字节.

并且从他的角度来看是编译器去适应平台.所以真正决定int占多少字节取决于你的device platforms.

事实上不管哪种模型short和char不管哪种model下都保持一致.

我们见得最多的就是ILP32LL模型.这样的模型下int和long已经pointer占4个字节 long long占8个字节.


PS:这个表非常easy记,中间的数字表明你是64bit还是32bit的机器.前面的I表示int,L表示long,LL表示long long,P就表示pointer.

位于数字前面的类型表示跟中间的bit数保持一致.举个样例:ILP32LL 就是ILP是32位,LL是64位.


一个int类型究竟占多少个字节,布布扣,bubuko.com

一个int类型究竟占多少个字节

标签:style   http   color   os   strong   for   art   re   

原文地址:http://www.cnblogs.com/hrhguanli/p/3867966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!