Hi all,
I have created a struct that holds status information which is 2 bit wide, each:
// status of menu
typedef union{
struct {
unsigned MENU:16;
};
struct{
unsigned MENU_MODE:2;
unsigned MENU_LEVEL:2;
unsigned SOURCE_BANK_TYPE:2;
unsigned MENU_ACTION:2;
unsigned DEST_BANK_TYPE:2;
};
} volatile menu_flags_t;
Now, I need to analyse these states, and I would like to use a switch command to increase readability:
// status of menu (see declaration in main.h)
menu_flags_t menu_flags;
// call functions that depend on menu level
switch(menu_flags.MENU_LEVEL){
// menu level 1:
case 1:
switch(pin){
case DIN_INC:
....
case DIN_DEC:
....
case DIN_ENTER:
....
}
break;
// menu level 2:
case 2: // menu_level == 2
switch(pin){
case DIN_INC:
....
case DIN_DEC:
....
}
break;
Unfortunately, the compiler complains:
main.c:316: warning 94: comparison is always true resp. false due to limited range of data type
main.c:316: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
Line 316 is the one with the first switch command. So how to do it correctly? Or is switch a No-No with bitfields?
Thanks, ilmenator