Search code examples
iphonexcodearmv6

How to you prevent blocks of code from compiling on ARMv6 for a fat binary?


I have a project for iPhone configured to compile for armv6 and armv7 architectures. And I need to exclude some code from compiling for armv6 architecture because it causes runtime crash on device (bad instruction exception).

Is there a define for armv6/armv7 compilation paths (such as "_DEBUG")?


Solution

  • First off, you don't need to prevent them from compiling, you need to prevent them from being executed. The crash is at runtime, after all, not compile time.

    That said, the easiest way to do this is to have two code paths, and compile the appropriate section based on architecture:

    #if defined _ARM_ARCH_7
    // your armv7 implementation goes here
    #elif defined _ARM_ARCH_6
    // your armv6 implementation goes here
    #elif defined __i386__
    // a simulator implementation could go here, if you had one
    #else
    #error Unknown Architecture!
    #endif