Bill
Bill

Reputation: 204

where is __OBJC2__?

from https://opensource.apple.com/tarballs/objc4/.
__OBJC2__ is still exist in objc4-787.1, but missing in objc4-818.2, so where is it?

__OBJC2__ in objc4-787.1

// Define __OBJC2__ for the benefit of our asm files.
#ifndef __OBJC2__
#   if TARGET_OS_OSX  &&  !TARGET_OS_IOSMAC  &&  __i386__
        // old ABI
#   else
#       define __OBJC2__ 1
#   endif
#endif

Upvotes: 0

Views: 265

Answers (1)

skaak
skaak

Reputation: 3018

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.

Upvotes: 1

Related Questions