enum
{
KEYBOARD_MINUS,
KEYBOARD_PAY = KEYBOARD_MINUS + 4,
AA0 = KEYBOARD_MINUS + 0, // does not compile
AA1 = KEYBOARD_MINUS + 1, // does not compile
AA2 = KEYBOARD_MINUS + 2,
AA3 = KEYBOARD_MINUS + 3,
AAA = 1 + KEYBOARD_MINUS, // does not compile
};
enum
{
A0,
A1,
A2,
A3,
A4,
A5,
A6,
A7,
A8,
A9,
BA0=1<<A0, // does not compile
BA1=1<<A1,
BA2=1<<A2,
BA3=1<<A3,
BA4=1<<A4,
BA5=1<<A5,
BA6=1<<A6,
BA7=1<<A7,
BA8=1<<A8,
BA9=1<<A9,
};
void main()
{
}
- - -
sdcc -v
SDCC : mcs51/gbz80/z80/z180/r2k/r3ka/ds390/pic16/pic14/TININative/ds400/hc08/s08
3.2.0 #8008 (Jul 6 2012) (MINGW32)
sdcc test.c
test.c:6: error 174: enumeration constant not an integer
test.c:7: error 174: enumeration constant not an integer
test.c:10: error 174: enumeration constant not an integer
test.c:25: error 174: enumeration constant not an integer
Some of the values are duplicates, so it might be just a misleading error message. But there seem to be false errors and missing errors...
enum
{
/* 0 */ KEYBOARD_MINUS,
/* 4 */ KEYBOARD_PAY = KEYBOARD_MINUS + 4,
/* 0 */ AA0 = KEYBOARD_MINUS + 0, // does not compile
/* 1 */ AA1 = KEYBOARD_MINUS + 1, // does not compile
/* 2 */ AA2 = KEYBOARD_MINUS + 2,
/* 3 */ AA3 = KEYBOARD_MINUS + 3,
/* 1 */ AAA = 1 + KEYBOARD_MINUS, // does not compile
};
enum
{
/* 0 */ A0,
/* 1 */ A1,
/* 2 */ A2,
/* 3 */ A3,
/* 4 */ A4,
/* 5 */ A5,
/* 6 */ A6,
/* 7 */ A7,
/* 8 */ A8,
/* 9 */ A9,
/* 1 */ BA0=1<<A0, // does not compile
/* 2 */ BA1=1<<A1,
/* 4 */ BA2=1<<A2,
/* 8 */ BA3=1<<A3,
/* 16 */ BA4=1<<A4,
/* 32 */ BA5=1<<A5,
/* 64 */ BA6=1<<A6,
/* 128 */ BA7=1<<A7,
/* 256 */ BA8=1<<A8,
/* 512 */ BA9=1<<A9,
};
I experienced this as well. My case is similar to yours, in that I'm using prior values within the same enumeration to assign values to subsequent values. For example,
typedef enum {
START_STATE = 0,
STATE_EARLY = START_STATE + 1,
STATE_LATER = STATE_EARLY + 1,
STATE_LATEST = STATE_LATER + 1
} MyState_e;
I'd suggest changing the title to "Enumeration values cannot be defined by prior values in the enumeration". These compiled fine with 3.1.0 but now throw an error with 3.2.0.
This is preventing me from using the compiler; My enums are actually from expanded defines which cannot be done differently
Duplicate values (but not names) are legal in enums and sometimes desired.
It seems like values of 0 or 1 are not permitted to be duplicated when using expressions. Previous enums do not need to be referenced:
enum
{
A0=0,
A1=1,
A2=2,
A3=3,
B0=A0+0, // does not compile
B1=A1+0, // does not compile
B2=A2+0,
B3=A3+0,
C0=0+0, // does not compile
C1=1+0, // does not compile
C2=2+0,
C3=3+0,
D0=A0,
D1=A1,
D2=A2,
D3=A3,
};
.
The bug was triggered by enumerated symbols explicitly assigned constant expressions equal to 0 or 1; it didn't matter if they were duplicates or unique.
Fixed in revision #8089.