This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

enum, out of range

Hello,

I have added U postfix to the integer but the problem still is the same.

I read following pages but didn't work.
http://www.keil.com/support/docs/3243.htm
http://www.keil.com/forum/14703/

#define M(x)         (u32)(1U << (x%32))

enum{
   eFirst = M(x)
   .....
   eLast = M(31)     // generate "integer operation result is out of range"
}

Can I avoid this warning?

Parents
  • I try to use unsigned 32bits in enum,

    On a 32-bit platforma, that ultimately cannot work.

    The key problem is not with the enum's underlying integer type, though. It's with the enum values. An enum constant, by definition of the programming language, is always of type (signed) int. So even though the enum's underlying type may be uint32_t, on a 32-bit platform no enum value can equal (1UL << 31), because that's bigger than INT_MAX. The actual value of that thing will instead be an undefined result; most likely INT_MIN, i.e. -(1<<31)

Reply
  • I try to use unsigned 32bits in enum,

    On a 32-bit platforma, that ultimately cannot work.

    The key problem is not with the enum's underlying integer type, though. It's with the enum values. An enum constant, by definition of the programming language, is always of type (signed) int. So even though the enum's underlying type may be uint32_t, on a 32-bit platform no enum value can equal (1UL << 31), because that's bigger than INT_MAX. The actual value of that thing will instead be an undefined result; most likely INT_MIN, i.e. -(1<<31)

Children