cancel
Showing results for 
Search instead for 
Did you mean: 

Cosmic CXSTM8 Comiler Error - Invalid Constant Expression

jrichards
Associate
Posted on July 03, 2011 at 23:15

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.

1 REPLY 1
Andrew Neil
Evangelist III
Posted on July 04, 2011 at 08:58

''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 them

first

!

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: 

http://www.8052.com/forum/read/29152

  It's not 8052-specific - and do make sure that you haven't made the very mistake mentioned there!