Objective c 枚举在Xcode 4.6中的作用类似于无符号整数,即使枚举被定义为有符号整数

Objective c 枚举在Xcode 4.6中的作用类似于无符号整数,即使枚举被定义为有符号整数,objective-c,xcode,Objective C,Xcode,我只能用xCode 4.6重新创建这个bug。使用Xcode 4.5,一切正常 问题是myVal具有正确的位结构来表示-1的int val。但是,它显示的值是4294967295,如果用无符号int表示,则它是相同位结构的值。您会注意到,如果我将myVal强制转换为int,它将显示正确的值。这很奇怪,因为枚举应该是一个int 下面是一个屏幕截图,显示了main末尾调试器中所有我的变量的值 声明enum类型的首选新方法是使用NS_enum宏,如本文所述:这可能是一个32位/64位问题:32位-1将

我只能用xCode 4.6重新创建这个bug。使用Xcode 4.5,一切正常

问题是myVal具有正确的位结构来表示-1的int val。但是,它显示的值是4294967295,如果用无符号int表示,则它是相同位结构的值。您会注意到,如果我将myVal强制转换为int,它将显示正确的值。这很奇怪,因为枚举应该是一个int

下面是一个屏幕截图,显示了main末尾调试器中所有我的变量的值


声明
enum
类型的首选新方法是使用
NS_enum
宏,如本文所述:

这可能是一个32位/64位问题:32位
-1
将变为正
4294967295
即使将其设置为有符号但64位的整数。将enum更改为
typedef NS_enum(BTEnumValue,NSInteger){…};
并查看这是否会产生预期的结果。@WDUK NS_ENUM将type作为第一个参数,名称作为第二个参数,因此您的示例必须看起来像
typedef NS_ENUM(NSInteger,BTEnumValue){…}
@VitalyS.抱歉,我忘了!问题似乎只与调试器如何显示值有关。这就是您要问的吗?还是您的程序出现了某种错误?
typedef enum : int {
    BTEnumValueNegOne = -1,
    BTEnumValueZero = 0,
    BTEnumValueOne = 1,
}BTEnumValue;

int main(int argc, const char * argv[])
{

@autoreleasepool {

    //on this line of code myVal is 0
    BTEnumValue myVal = BTEnumValueZero;

    //we are adding -1 to the value of zero
    myVal += BTEnumValueNegOne;

    //at this moment myVal has the exact bit stucture 
    //of a signed int at -1, but it is displaying it 
    //as a unsigned int, so its value is 4294967295

    //however, if i cast the enum (which should already 
    //be an int with a signing) to an int, it displays 
    //the correct value of -1
    int myIntVal = (int)myVal;

    }
    return 0;
}