Enum acts like unsigned int in Xcode 4.6 even when enum is defined as signed int

I was only able to recover this error with xCode 4.6. Everything works as expected using Xcode 4.5

The problem is that myVal has the correct bit structure to represent int val -1. However, it shows the value 4294967295, which is the value of the same bit structure when represented by an unsigned int. You will notice that if I pass myVal to int it will show the correct value. This is weird because the enum must be int to to.

here is a screenshot showing the value of all my variables in the debugger at the end of main. http://cl.ly/image/190s0a1P1b1t

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;
}

      

+3


source to share


1 answer


New, preferred way to declare types enum

with a macro NS_ENUM

, as described in this post: http://nshipster.com/ns_enum-ns_options/



0


source







All Articles