Advertisement

Linux 64bit preprocessors

Started by March 25, 2008 06:04 AM
7 comments, last by JPulham 16 years, 8 months ago
Is there a preprocessor definition I can '#ifdef' to check if the code is compiling 64bit? (like in windows -> 'WIN32' || 'WIN64')
That's OS specific. The Windows headers for MinGW likely define WIN32/WIN64. There is no such thing on GNU/Linux systems, AFAIK (where it wouldn't make much sense anyway: running "Linux64" tells you nothing about the integer size used by the C compiler, endianness, etc.)

cpp -dM /dev/null | less will give you a list of what is available for your platform.
Advertisement
Maybe this link is interesting:
http://predef.sourceforge.net/prearch.html#sec7
Quote: Original post by nmi
Maybe this link is interesting:
http://predef.sourceforge.net/prearch.html#sec7

I think that particular section is for the Itanium family. x86-64 likely falls under AMD64.
Quote: Original post by Null and Void
Quote: Original post by nmi
Maybe this link is interesting:
http://predef.sourceforge.net/prearch.html#sec7

I think that particular section is for the Itanium family. x86-64 likely falls under AMD64.


Ups, thx for noticing that.
Most not yet all unixs use the LP64 model, so a check for the define __LP64__ or _LP64 should catch most of the them. LP64 data model defines the following:
Quote:
...long int and pointer both use 64-bits and int uses 32-bit.


edit:
So a combination of all of these methods should catch the it.
#ifdef __GNUC__#	if defined __LP64__ || defined _LP64#			define SYSTEM_BITS 64#	elif defined __x86_64__ || defined __ia64__ || defined_IA64 || defined__IA64__				|| defined __amd64__ || defined __amd64 || defined __x86_64__ || defined __x86_64				#				define SYSTEM_BITS 64#else#		define SYSTEM_BITS 32		extern char dummy_bit_checker[(sizeof(long) == sizeof(void*) == 4) ? 1 :-1];#endif


[Edited by - dmail on March 25, 2008 10:43:45 AM]
Advertisement
I have had no problems thusfar by using #ifdef __x86_64__ on Linux.
Quote: Original post by DaBono
I have had no problems thusfar by using #ifdef __x86_64__ on Linux.


I'd never spotted that one. It could be useful one day. Thanks!
Thanks for the replies. I think I've got what I need.

This topic is closed to new replies.

Advertisement