- 略
- 略
- 假定你要写一个程序要在两台机器上都能运行,它们的默认整型大小不同,分别是16位和32位,长整型大小分别是32位和64位,一些足够小的值可以适合任意一台机器,但是一些比较大的值要求用32位,一个可能简单的办法是对所有的值都使用长整型,但是这种方法对于能够在16位机器上运行的就会浪费时间和空间,在32位机器上也存在时间和空间的浪费问题,你如何声明这些变量使他们在两种机器上都能运行,正确的方法是避免在任意一台机器上编译程序之前更改它们的声明,提示:尝试在一个头文件中包含对不同机器的特殊声明
答:在32位机器上
typedef signed char-----------int8
typedef short int----------------int16
typedef int-----------------------int32
typedef int-----------------------defint8
typedef int-----------------------defint16
typedef int-----------------------defint32
在16位机器上
typedef signed char-----------int8
typedef int------------------------int16
typedef long int------------------int32
typedef int------------------------defint8
typedef int------------------------defint16
typedef long int-----------------defint32
- 假定你有一个程序