• Create Account

### #ActualAllEightUp

Posted 21 April 2013 - 06:12 PM

It is only partially portable.  For Visual Studio it is fine since CMake only outputs 32 or 64 bit specific solutions.  Unfortunately though, since it is a project generation time test it won't work on items which allow switching between 32 and 64 bits on the fly, for instance Xcode automatically inserts both targets.  As such, you need to really use a compile time test.  A version I've been using which seems to be pretty consistent is:

#define __STDC_LIMIT_MACROS
#include <stdint.h>

#if UINTPTR_MAX == 0xffffffff
# define BUILDING_32BIT
#elif UINTPTR_MAX == 0xffffffffffffffff
# define BUILDING_64BIT
#else
# error Unknown architecture.
#endif



Note:

Obviously this only works on compilers with stdint, VC2010-2012 have it, 2008 didn't and you have to deal with it using specific compiler tricks.

### #1AllEightUp

Posted 21 April 2013 - 06:06 PM

It is only partially portable.  For Visual Studio it is fine since CMake only outputs 32 or 64 bit specific solutions.  Unfortunately though, since it is a project generation time test it won't work on items which allow switching between 32 and 64 bits on the fly, for instance Xcode automatically inserts both targets.  As such, you need to really use a compile time test.  A version I've been using which seems to be pretty consistent is:

#define __STDC_LIMIT_MACROS
#include <stdint.h>

#if UINTPTR_MAX == 0xffffffff
# define BUILDING_32BIT
#elif UINTPTR_MAX == 0xffffffffffffffff
# define BUILDING_64BIT
#else
# error Unknown architecture.
#endif


PARTNERS