[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: C/C++ 中用哪个宏来区分32位与64位系统?



2012/4/26 Plain_Text <resation@gmail.com>:
>
>
>   从 C/C++ 程序员的角度来看,32位系统与64位系统的本质区别是什么?注意
> 这里说的是广义的32位和64位,而不特定指 i386, amd64. 是否是指针长度不一样?
> 我现在这样区分两者:
>
> #if __SIZEOF_POINTER__ == 4
>        /* 32位系统 */
> #elif __SIZEOF_POINTER__ == 8
>        /* 64位系统 */
> #endif
>
>   这是 GCC 下的标准的做法吗?另外顺便问一下,在 Windows 下的 MSVC 里,
> 该用什么宏来区分两者? Windows 似乎只支持i386, amd64, 应该容易应付。不过
> 最新的 Windows 8 好像也开始支持 MIPS 系统。
>
>

如果只是区分 32-bit/64-bit, 可以判断 sizeof(long) 或者 sizeof(void*),因为目前主流 64-bit
系统都是 LP64 (long 和 pointer 是 64-bit)。这个与指令集不直接相关,所以应该也可用于区分 MIPS, ARM
等。

如果需要确切的指令集,每种系统都有自己的宏,可以查看 GCC 手册。

>
>
>
> --
> To UNSUBSCRIBE, email to debian-chinese-gb-REQUEST@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
> Archive: [🔎] 20120426234014.GA2646@localhost.localdomain">http://lists.debian.org/[🔎] 20120426234014.GA2646@localhost.localdomain
>

Reply to: