0

I'd like to cross-compile specific 32-bit and 64-bit code using an #if directive based on gcc switches.

Are there any macros set by GCC I could use instead of setting a macro using the -D switch?

Can I somehow pick up the switches used in the gcc command options to test them at the preprocessor stage?

So far I found out that -m64 defines on my 64-bit machine

   __x86_64__

whereas -m32 undefines

   __i386__ __i486__ __i586__ __i686__
OneArb
  • 453
  • 2
  • 14

1 Answers1

2

You could use INT_MAX value from <limits.h>. This is C, so independent to compiler.

You can also check https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html to have some other predefined macros based on compiler options.

In general in recent time, it is recommend to write code portable, also with if that tests conditions that true only on specific architectures. Optimizer will remove unneeded branches.

Giacomo Catenazzi
  • 8,519
  • 2
  • 24
  • 32
  • How relevant this value when cross-compiling? – OneArb Mar 18 '18 at 22:46
  • These values are target dependent (like types and binary code). The host do no matter. Headers are also target dependent, and if you look carefully, you see `#ifdef` with arch name in normal headers (see https://stackoverflow.com/questions/152016/detecting-cpu-architecture-compile-time). Note: on recent time, it is preferred not to do cross-compiling, but using an emulator and run gcc from there: there are a lot less problems with third party libraries (often their building scripts do not support cross-compiling). – Giacomo Catenazzi Mar 19 '18 at 08:30