Search code examples
cmsp430iar

expected a ")" in IAR IDE


I got the error Error[Pe018]: expected a ")" at CPU_state == cpuStateOff.
When I change cpuStateOff to 0 it's OK. I don't know why.

In my PERIPHERAL_APP.h:

#ifndef __PERIPHERAL_APP_H
#define __PERIPHERAL_APP_H
// CPU state
#define CPU_STATE_OFF     0;
#define CPU_STATE_ON      1;
#endif

In my main.c:

#include "PERIPHERAL_APP.h"
void main( void )
{
    initMSP430();  
    _EINT();                              
    for (;;)
    {
        if (cpuState == CPU_STATE_OFF ) // The error is hear 
        {
            __bis_SR_register(LPM3_bits);
        }
        else
        {
            __bis_SR_register(LPM0_bits); 
        } 
    } 
}

Solution

  • Preprocessor macros are not C statements, and therefore doesn't need a statement terminator like ;.

    What happens is that when the preprocessor replaces the macro cpuStateOff it uses the whole body of the macro, i.e. 0; which results in code like

    if (CPU_state == 0; ) // Code after macro replacement
    

    Most compilers and environments have options to stop after preprocessing, if you use it you can see exactly what code the compiler "proper" will see.