In a C project, at some places, I'd like to compile different code, depending on whether or not the compilation happens for x64
. Of course, CPP macros are the route to go.
However, on this page (which should be the authoritative reference), there is no predefined macro just for x64.
Out of curiosity, did I miss something?
I am aware that I easily can solve the actual problem:
First, according to the reference above, if I would like to stick with predefined macros, I could do something like that:
#if defined (_M_AMD64) && (_M_AMD64 == 100) && !defined (_M_ARM64EC)
....
#endif
The first two conditions make sure we compile for x64
or arm64ec
, the third condition makes sure we do not compile for arm64ec
, which together should make sure we compile for x64
.
Second, I could define my own macro in the project settings for x64 configurations and use that instead of a predefined one:
#ifdef MY_OWN_X64_FLAG
...
#endif
While they solve the problem, both methods are not intuitive and elegant. Is there really no predefined macro that we can use to test for x64
only with one simple #ifdef
?