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
  • Thanks for your replies,

    I had tried the followings, Keil generates the warning.(Keil v5.16a)

    typedef unsigned int    u32;
    
    1) #define M(x) (u32)( ((u32)1) << ((x)%32))
    
    2) #define M(x) (u32)( (1U) << ((x)%32))
    
    3) if I write also (u32)0x80000000 instead of M(31) in enum
    
    
    #define L(x) (u32)((1U) << ((x)%32))
    #define T()  ((u32)0x80000000)
    #define M(x) (u32)(((u32)1) << (x%32))
    
    enum{
            test_1=M(31),
            test_2=L(31),
            test_3=T(),
    };
    
    
    
    compiling Gprs.c...
    ..\src\Gprs.c(14): warning:  #66-D: enumeration value is out of "int" range
            test_1=
    (31),
    ..\src\Gprs.c(15): warning:  #66-D: enumeration value is out of "int" range
            test_2=
    (31),
    ..\src\Gprs.c(16): warning:  #66-D: enumeration value is out of "int" range
            test_3=
    
    

Reply
  • Thanks for your replies,

    I had tried the followings, Keil generates the warning.(Keil v5.16a)

    typedef unsigned int    u32;
    
    1) #define M(x) (u32)( ((u32)1) << ((x)%32))
    
    2) #define M(x) (u32)( (1U) << ((x)%32))
    
    3) if I write also (u32)0x80000000 instead of M(31) in enum
    
    
    #define L(x) (u32)((1U) << ((x)%32))
    #define T()  ((u32)0x80000000)
    #define M(x) (u32)(((u32)1) << (x%32))
    
    enum{
            test_1=M(31),
            test_2=L(31),
            test_3=T(),
    };
    
    
    
    compiling Gprs.c...
    ..\src\Gprs.c(14): warning:  #66-D: enumeration value is out of "int" range
            test_1=
    (31),
    ..\src\Gprs.c(15): warning:  #66-D: enumeration value is out of "int" range
            test_2=
    (31),
    ..\src\Gprs.c(16): warning:  #66-D: enumeration value is out of "int" range
            test_3=
    
    

Children