ilmenator Posted July 21, 2008 Report Share Posted July 21, 2008 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 DOGLine 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 Quote Link to comment Share on other sites More sharing options...
stryd_one Posted July 21, 2008 Report Share Posted July 21, 2008 Ahhh good old evelyn.Alas you can't pass an aggregate as an argument in SDCC, it'll be passing the address, and seeing as the address will never change, the optimiser has a fit.Tryfoo = menu_flags.MENU_LEVEL;switch (foo)Or something... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.