I think the compiler sets that flag.
The following program shows that the flag is set, even though it does not include any Objective-C headers. The only giveaway is that the file is a .m
thus my conclusion.
// main.m
#include <stdio.h>
int main(int argc, const char * argv[])
{
printf( "Hallo world\n" );
printf( "Definition %d\n", __OBJC2__ );
}
Compile with
cc main.m
Compiler
cc --version
Apple clang version 12.0.0 (clang-1200.0.32.29)
Output
Hallo world
Definition 1
EDIT
Based on GCC dump preprocessor defines I was able to verify this. Just create an empty .m
file and run
cc -dM -E empty.m
or better run
cc -dM -E empty.m | grep OBJ
and you will see the definition. Also compare to a C file e.g.
cc -dM -E empty.c | grep OBJ
where it is NOT defined.