3

I used the answer from Determining 32 vs 64 bit in C++ to make this:

#ifndef AVUNA_CFG
#define AVUNA_CFG
#if _WIN32 || _WIN64
#if _WIN64
#define BIT64
#else
#define BIT32
#endif
#endif

// Check GCC
#if __GNUC__
#if __x86_64__ || __ppc64__
#define BIT64
#else
#define BIT32
#endif
#endif
#endif

However, this doesn't seem to work when specifying -m32 to GCC for cross compiling, so it always says BIT64. Is there any defines I can use for this purpose?

Community
  • 1
  • 1
JavaProphet
  • 931
  • 14
  • 29
  • Also, for gcc, look at `__LP64__` and `_LP64` for detecting 64bit compiles: "*These macros are defined, with value 1, if (and only if) the compilation is for a target where long int and pointer both use 64-bits and int uses 32-bit*." – Remy Lebeau Aug 12 '15 at 00:53
  • @RemyLebeau: The only time there would be a difference is if someone did `#define _WIN32 0`, and then your suggested code would be worse. – Ben Voigt Aug 12 '15 at 00:54
  • 2
    @RemyLebeau I don't think you can use sizeof in a preprocessor? – JavaProphet Aug 12 '15 at 00:56
  • @JavaProphet: You are right. I forgot about that caveat. – Remy Lebeau Aug 12 '15 at 01:18
  • The recent addition of -mx32 may complicate full answer to this even further – technosaurus Aug 12 '15 at 01:20
  • If `__ILP32__` is defined on an otherwise 64 bit system, ARCH=x32... Where the 64 bit system uses pointers that are 32 bits (and some other minor differences) – technosaurus Aug 12 '15 at 01:30
  • You could setup your Makefile or whatever to also pass a define whenever you pass `-m32` – M.M Aug 12 '15 at 01:35

1 Answers1

0

I ended up using an Eclipse-define because I have two different run configurations for 32/64-bit cross compile. Works well.

JavaProphet
  • 931
  • 14
  • 29