I'm using Clang's primitive-boxing feature to pack an enumeration member into NSNumber
The Boxed Enums section of the Clang doc about this says that the compiler boxes enumeration members into integers, unless the type is specified.
Funnily enough, I get different sizes of integers depending on the way I'm passing the enumeration member to the method. I've been able to isolate the case down to the following code
typedef enum _MyEnum {
MyEnumMember1 = 1000
} MyEnum;
- (void)testEnumerationBoxing
{
NSNumber *numberA = [self testA];
NSNumber *numberB = [self testB:MyEnumMember1];
CFNumberType numberTypeA = CFNumberGetType((__bridge CFNumberRef) numberA);
CFNumberType numberTypeB = CFNumberGetType((__bridge CFNumberRef) numberB);
NSLog(@"CF Number type for A: %lu; B: %lu", numberTypeA, numberTypeB);
}
- (NSNumber *)testA
{
return @(MyEnumMember1);
}
- (NSNumber *)testB:(MyEnum)enumMember
{
return @(enumMember);
}
The console output is
CF Number type for A: 3; B: 4
(the first one is kCFNumberSInt32Type
, the second one is kCFNumberSInt64Type
)
If I change declaration to typedef enum _MyEnum : int
I see the same result for both: kCFNumberSInt32Type
.
Why does the size of the integer differ between the two methods of boxing?