2011-07-03 02:15 PM
I'm porting some code designed to run on a Nordic nRF8200 to an STM8L152C6. The code was orginally compiled using Keil C5. I am using the Cosmic CXSTM8 compiler.
I am getting a compiler error 'Invalid Constant Expression' in the CASE: line of a switch statement that I cannot understand. code snippet is included below. switch (pipe_num) { case PIPE_LINK_LOSS_ALERT_ALERT_LEVEL_RX: alert_handle_on_link_loss = (alert_level_t)buffer[0]; break; default: break; } pipe_num is a locally defined uint8_t, and #define PIPE_LINK_LOSS_ALERT_ALERT_LEVEL_RX 6 is declared in an included header file. I cannot understand what the compiler is taking exception to in this case. If anyone could help I'd really appreciate it.2011-07-03 11:58 PM
''I am getting a compiler error 'Invalid Constant Expression' in the CASE: line of a switch statement that I cannot understand''
First, are there any other errors or warnings before this? If so, fix themfirst
! You mean this line:
case PIPE_LINK_LOSS_ALERT_ALERT_LEVEL_RX:
The only constant expression there is PIPE_LINK_LOSS_ALERT_ALERT_LEVEL_RX - so re-check that definition. Are you sure it isn't, for example, affected by some #if conditional compilation options that you've not (properly) set-up in your project...? Howver,
alert_handle_on_link_loss = (alert_level_t)buffer[0];
is also a constant expression - are you sure it's not complaining about that?''I cannot understand what the compiler is taking exception to in this case'' Have you tried looking at the preprocessor output? See: It's not 8052-specific - and do make sure that you haven't made the very mistake mentioned there!