开发者

Is there a a define for 64 bit in gcc [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Detecting 64bit compile in C

I want my program to run on both 32 bit and 64 bit Lin开发者_开发知识库ux OS. So In my C code, I want the compiler to know when it is compiling for a 32 bit and 64 bit architecture. So, I need something like that

#ifdef X64
...
#else
...
#endif

Is there any such define in gcc?


I know of these:

__i386__    
__x86_64__  

I don't know how reliable they are.

The best option would be adding -DMY_32BIT to the Makefile's compile line when compiling for 32 bits and checking for MY_32BIT on your code. That way you can be sure.


There is __WORDSIZE in limits.h:

#include <limits.h>
#if ( __WORDSIZE == 64 )
#define BUILD_64   1
#endif

This is relatively portable (due to POSIX), but may fail in obscure environments or on windows.


Look here:

#ifdef __x86_64
...
#endif
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜