日历
网志分类
展开全部
· ***    All     ***
· ***    Mood    ***
· ***    Life    ***
· *** Technology ***
· ***     Yc     ***
· ***  Cartoon   ***
· *** Collection ***
· ***  Unsorted  ***
媒体播放器

Get the Flash Player to see this player.
SkyDrive is currently not available.

站内搜索
友情链接
· 我的歪酷 非非共享界
· 风雨妖虹
· kingbeful@csdn
· 手心的太阳@瞬间十年
· Moment@Travis
· 江南麒麟居
· εз毛线团εз
· 乌拉的neverland
· 碾过的日子 闲也陶陶
· 狡兔三窟 *^.^*
· 橄榄林的风
· 水色の街
· Powerful and delicate, Life struggling
· 阿德咖吧
· 陷阱
· 风之华
· vkobe的Neverland@@
· 白日梦已死 · 伤越夜海
· 望天
· 空の軌跡
· 没什么好东西的空间
· 心情...咖啡屋
· 随风独自凉
· Some where i belong
· .★·°双晨·故事°☆ .
· BigWorld的记事本
· *Sara's*
· 人生若只如初见
· 宠辱不惊闲看庭前花开花落·去留无意漫随天外云卷云舒
· 我思我不在
· 飞扬飘雨
· lazy的猫猫
常用链接
· [Google]
· [Google Accounts]
· [IT Items]
· [Telnet@Yanxi]
· [Wikipedia]
· [Linux Manpages]
· [Mofile.com]
· [163888.net]
· [fm.qq.com]
· [Proxy]
· [Animepaper.net]
· [FreeproxySite]
· [gonwan@fc2]
· [skydrive.live.com]
· [gonwan@lifelogger]

订阅 RSS

0109816

歪酷博客

逆さまの蝶
In this Craziness
Uncertainy
一人一人の想いを
僕らは何処かに遺せるだろうか

In this Craziness
You gave me life
一つの想いを
僕らは何処まで守れるだろうか



« 上一篇: Cross-platform Development in C/C++ (5) 下一篇: vs2005一般头文件的写法 »
丸子·酱 @ 2008-08-28 09:38

Item 21: Avoid Problems Related to the Size and Organization of Types

    有件事情好像我一直都搞错了, C/C++最基本的数据类型的大小. 标准并没有规定char/short/int/long的数据大小, 而只规定了它们之间的关系:
    sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)
    VC的话, x86-32/x86-64的机器大小都是一样的, 分别为1, 2, 4, 4, 8. 注意long long是c99中加入的. 如果gcc的话, 我没有研究过. c99中加入了一系列的macro: (u)int8_t, (u)int16_t, (u)int32_t, (u)int64_t似乎能解决一些问题, 但是vs2005目前还不支持.

    第二个问题: 一个char到底包含多少个byte? 多少个bit?
    也许你这次会谨慎的说, x86的话, 分别是1和8. 嗯.. 对于byte来说, 标准说就是一个byte, 但是一个byte是多少个bit是没有说明的, 也就是说, 8,16,32,64,128都是可以的=v=.
   
     第三个问题, word是个什么东西?
     最初看到这个还是在ICS课的教材. 今天又看到了说for循环为什么一般都用int来做, 理由是cpu做的事情最少最高效(x86是32为寻址的). 而word一般是指natural的数据大小(natural不知道怎么翻译), x86就是32bit. 可是VC下的WORD显然被定义成了16bit的short啊, 怎么回事? 唉.. 我直接抄wikipedia吧:
    Sometimes the size of a word is defined to be a particular value for compatibility with earlier computers. The most common microprocessors used in personal computers (for instance, the Intel Pentiums and AMD Athlons) are an example of this. Their IA-32 architecture is an extension of the original Intel 8086 design which had a word size of 16 bits. The IA-32 processors still support 8086 (x86) programs, so the meaning of "word" in the IA-32 context was kept the same, and is still said to be 16 bits, despite the fact that they at times (especially when the default operand size is 32-bit) operate largely like a machine with a 32 bit word size. Similarly in the newer x86-64 architecture, a "word" is still 16 bits, although 64-bit ("quadruple word") operands may be more common.


参考:
*) How should I decide which integer type to use?
*) Why aren't the sizes of the standard types precisely defined?
*) Since C doesn't define sizes exactly, I've been using typedefs like int16 and int32. I can then define these typedefs to be int, short, long, etc. depending on what machine I'm using. That should solve everything, right?
*) C++ Integer Data Types
*) Integer (computer science)
*) Word (computing)


曾经的这一天...



评论 / 个人网页 / 扔小纸条
* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 


 

分类小组论坛
杂谈 , 娱乐、八卦 , 文学、艺术 , 体育 , 旅游、同城 , 象牙塔 , 情感 , 时尚、生活 , 星座 , 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定