Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What predefined macro can I use to detect the target architecture in Clang?

Tags:

macros

clang

arm

I would like to write code depending on whether the target architecture is e.g. armv7, armv7s, or arm64.

The reason that I can't use sysctlbyname is that this would give me the underlying architecture at runtime, but when arm64 e.g. simulates armv7, sysctl (seemingly) still reports arm64.

like image 273
oleks Avatar asked May 29 '14 13:05

oleks


2 Answers

Although this is not a 100% answer to the question, but may be useful:

When using clang, you can discern between 32 bit arm and 64 bit arm using:

__arm__ which is defined for 32bit arm, and 32bit arm only.

__aarch64__ which is defined for 64bit arm, and 64bit arm only.

like image 183
Bram Avatar answered Oct 04 '22 00:10

Bram


clang --target=... -mcpu=... -E - -dM </dev/null will output all the pre-defined preprocessor macros (similar works for gcc, too)

I don't see single macro that provides the answer, but you can probably use some combination of __ARM_ARCH and defined(__ARM_ARCH_*).

like image 31
scott Avatar answered Oct 03 '22 22:10

scott