Search code examples
automatic-ref-countingclangcompiler-flags

How to determine compiler is currently in ARC mode?


I have several inline static C functions. And I call Objective-C codes including [-release].

The problem is I have to compile this code both of ARC or non-ARC targets. So I think I need conditional compilation by predefined compiler flag. What flag should I use for this?


Solution

  • From http://lists.apple.com/archives/xcode-users/2011/Aug/msg00252.html:

    The LLVM Compiler's checks are called __has_feature. ARC is one of the features you can check for.

    #ifndef __has_feature
    // not LLVM Compiler
    #define __has_feature(x) 0
    #endif
    
    #if __has_feature(objc_arc)
    // compiling with ARC
    #else
    // compiling without ARC
    #endif