Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Expected a statement" error in embedded C

Tags:

c

arm

keil

arm7

I'm getting error like "expected an statement"

my code is as follows

#define IN_Tamper    0X00001000     /*P2.12 = EINT2*/
#define DIR_IN_Tamper    { FIO2DIR &= ~0X00001000 ; } 

/* main */
DIR_IN_Tamper(); 
if(((IN_Tamper >> 12) & 0x01) == 1)
            BUZZER_ON();
         else
            BUZZER_OFF();   

I'm getting error saying

  1. Expected an statement for DIR_IN_Tamper();

  2. expected a statement for the else part.....

like image 359
YMJ Avatar asked Jul 12 '13 10:07

YMJ


1 Answers

The C preprocessor is (at least in the way you use it) just a simple search-and-replace, so you're effectively running

/* main */
{ FIO2DIR &= ~0X00001000 ; } (); 

This doesn't make any sense. Remove the parentheses in the line

DIR_IN_Tamper(); 

For BUZZER_ON and BUZZER_OFF, you want to remove the parentheses as well. If the macro isn't enclosed in curly braces, you also want to add those, like

if(((IN_Tamper >> 12) & 0x01) == 1) {
    BUZZER_ON
} else {
    BUZZER_OFF
}
like image 127
phihag Avatar answered Oct 03 '22 00:10

phihag