心无尘土
一段平凡的日子,一段流逝的岁月
1.2 没有强制定义标准类型大小,这样可以适应不同机器并且大部分情况下没有必要用具体大小,还可以隐藏执行细节。(文档加上个人理解,不对勿怪-yama)
Why aren't the sizes of the standard types precisely defined?

Though C is considered relatively low-level as high-level languages go, it does take the position that the exact size of an object (i.e. in bits) is an implementation detail. (The only place where C lets you specify a size in bits is in bit-fields within structures; see questions 2.25 and 2.26) Most programs do not need precise control over these sizes; many programs that do try to achieve this control would be better off if they didn't.

Type int is supposed to represent a machine's natural word size. It's the right type to use for most integer variables; see question 1.1 for other guidelines. See also questions12.42 and 20.5

1.3具体自己定义16,32位int来实现各种机器上面的整数是没有必要的。因为要注意很多事情哦(文档加上个人理解,不对勿怪-yama)
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?

If you truly need control over exact type sizes, this is the right approach. There remain several things to be aware of:
  • There might not be an exact match on some machines. (There are, for example, 36-bit machines.)
  • A typedef like int16 or int32 accomplishes nothing if its intended meaning is ``at least'' the specified size, because types int and long are already essentially defined as being ``at least 16 bits'' and ``at least 32 bits,'' respectively.
  • Typedefs will never do anything about byte order problems (e.g. if you're trying to interchange data or conform to externally-imposed storage layouts).
  • You no longer have to define your own typedefs, because the Standard header <inttypes.h> contains a complete set.
1.4 机器上面64位的类型的支持是因为编译器大部分实现了long long类型或者他的扩展_longlong.也可以来定义short int为16位,int为32位,long int为64位来实现。(文档加上个人理解,不对勿怪-yama)

 What should the 64-bit type be on a machine that can support it?

  The new C99 Standard specifies type long long as effectively being at least 64 bits, and this type has been implemented by a number of compilers for some time. (Others have implemented extensions such as __longlong.) On the other hand, it's also appropriate to implement type short int as 16, int as 32, and long int as 64 bits, and some compilers do.

posted on 2006-07-28 14:19 Yama的家 阅读(297) 评论(0)  编辑 收藏 引用 所属分类: 标准C
只有注册用户登录后才能发表评论。

<2006年10月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(5)

随笔分类(66)

相册

积分与排名

  • 积分 - 42794
  • 排名 - 137

最新评论

阅读排行榜