在我的Solaris 10 update 9系统上,以下命令产生:
#isainfo -b
64
Run Code Online (Sandbox Code Playgroud)
但是,如果我在C中使用limits.h创建以下程序,我会得到:
#include <stdio.h>
#include <limits.h>
int main(void)
{
printf("Maximum integer value on this system is = %d\n", INT_MAX);
}
Run Code Online (Sandbox Code Playgroud)
gcc on64.c -o on64 ./on64 Maximum integer value on this system is = 2147483647
我期待更大的结果,因为系统运行在64位.这似乎是一个32位的结果.这是编译器问题吗?
64位平台有各种编程模型,http://www.unix.org/version2/whatsnew/lp64_wp.html,包括:
64位Solaris 10使用LP64模型(http://www.sun.com/software/solaris/faqs/64bit.xml#q4):
问:Solaris操作系统使用的数据模型是什么?
答:LP64是事实上的行业标准.L代表长,P代表指针.两者都是64位,而int是32位.
除了"64位编程模型:为什么选择LP64?" 上面提到的论文,你可能想看看Raymond Chen对Win64选择LLP64模型的原因的解释,因为它可能有助于支持unix.org文档中的各种基本原理和参数:http://blogs.msdn.com/b/ oldnewthing /存档/ 2005/03/31/363790.aspx
无论平台如何,gcc上的"int"类型都是32位."long"类型在32位平台上为32位,在64位平台上为64位.
为了不那么模糊,你可以使用C99类型:
#include <stdint.h>
int32_t i32;
int64_t i64;
Run Code Online (Sandbox Code Playgroud)