I have a problem with the "switch":
QUOTE
char data[4]={0};
const char adr1=240;
const char adr2=241;
const char adr3=242;
const char adr4=243;
void main(){
char dev=0;
//some other code
switch(data[1]){
case adr1:
dev=0;
break;
case adr2:
dev=1;
break;
case adr3:
dev=2;
break;
case adr4:
dev=3;
break;
default:
dev=-1;
break;
}
}
const char adr1=240;
const char adr2=241;
const char adr3=242;
const char adr4=243;
void main(){
char dev=0;
//some other code
switch(data[1]){
case adr1:
dev=0;
break;
case adr2:
dev=1;
break;
case adr3:
dev=2;
break;
case adr4:
dev=3;
break;
default:
dev=-1;
break;
}
}
the compiler says "error: non-constant argument in 'case' expression" but the adr1,2,3,4 are constants!
If i replace "const char adr1=240;" with "#define adr1 240" but then i get the error:
error: missing colon
error: missing right brace
error: missing right paren
error: failure
The code works fine if i replace the adr1,2,... with the numbers but why is it not working with constants?
Tom
