cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to use a compiler switch for defining preprocessor directives. The controller is STM32F072VC and IAR Workbench is used.

JK.4
Associate II
#define EXICOM_2KW              1
#define EXICOM_1KWH             0
 
 
 
#if EXICOM_2KW
#define EXICOM_RX_MAX_SIZE              60
#define EXICOM_TX_MAX_SIZE              18
#define EXICOM_RX_INDEX_MAX             60
#define EXI_ACTIVE                      0
#elif EXICOM_1KWH
#define EXICOM_RX_MAX_SIZE              12
#define EXICOM_TX_MAX_SIZE              12
#define EXICOM_RX_INDEX_MAX             12
#endif
 
 
extern char EXICOM_Tx_Buffer[EXICOM_TX_MAX_SIZE];
extern uint8_t EXICOM_Rx_Buffer[EXICOM_RX_MAX_SIZE];

When EXICOM_2KW is 1, "EXICOM_RX_MAX_SIZE", "EXICOM_TX_MAX_SIZE", "EXICOM_RX_INDEX_MAX" are not taking their respective values(60,10,60).

I am getting a warning like subscript out of range for EXICOM_Rx_Buffer.

I am not sure whether we can use compiler switch for an array declaration.

Kindly help!!

1 REPLY 1
Andrew Neil
Evangelist III

Doesn't the IAR documentation tell you how to do this? If not, contact IAR support - that's what you're paying the licence fee for!

"I am getting a warning like (sic) subscript out of range for EXICOM_Rx_Buffer"

What do you mean, "like" ?

Copy & paste the complete message that you're getting.

When having preprocessor problems like this, you should examine the preprocessor output to see what the compiler is actually seeing - again, the IAR documentation should tell you how to do that, or contact IAR support.

You've shown 'extern' declarations - do these match the definitions?

"I am not sure whether we can use compiler switch for an array declaration"

It's just a preprocessor symbol - it's exactly as if it had been defined in the source code using #define