"Initializer is not a compile-time constant" works in .mm?

I am puzzled by the situation that I am observing and will love some understanding. First, I use Xcode 5, with LLVM 5 compiler options set by default.

I have a line in a .m file, for example:

static NSArray * const kSchemaVersions = @[@"1"]; 

And, as expected, I see a compiler error saying Initializer element is not a compile-time constant.

However, if I put the same line in a .mm file (Objective C ++), the compiler does not complain.

I fully understand why this should not work, but I do not understand why it looks.

Thoughts?

+4
source share
1 answer

As you mentioned, in C and Objective-C static variables can only be initialized with compile-time constants. In C ++ (and therefore Objective-C ++), on the other hand, static variables are assigned at runtime before main starts.

For more details see Eli Bendersky Intermittent Global Initialization in C and C ++

+7
source

Source: https://habr.com/ru/post/1493544/


All Articles