Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: #29: expected an expression in C

my code contains

#define READ_TAMPER_PIN()   {((FIO2PIN & PIN_TAMPER) >> 12) ;}

where PIN_TAMPER is again a macro-

 #define PIN_TAMPER     0x00001000;

in one of the header file, and it is called in main() like

x = READ_TAMPER_PIN();  

it gives an error saying "error: #29: expected an expression"

what could be possible mistake that I'm making here??

like image 749
YMJ Avatar asked Oct 03 '22 12:10

YMJ


2 Answers

The braces and semicolon in your macro are wrong. Use:

#define READ_TAMPER_PIN()   ((FIO2PIN & PIN_TAMPER) >> 12)
like image 198
Carl Norum Avatar answered Oct 07 '22 18:10

Carl Norum


According to c99 standard (§6.10.3 #10)

A preprocessing directive of the form

# define identifier lparen identifier-listopt ) replacement-list new-line

# define identifier lparen ... ) replacement-list new-line

# define identifier lparen identifier-list , ... ) replacement-list new-line

defines a function-like macro with arguments, similar syntactically to a function call. The parameters are specified by the optional list of identifiers, whose scope extends from their declaration in the identifier list until the new-line character that terminates the #define preprocessing directive. Each subsequent instance of the function-like macro name followed by a ( as the next preprocessing token introduces the sequence of preprocessing tokens that is replaced by the replacement list in the definition (an invocation of the macro). The replaced sequence of preprocessing tokens is terminated by the matching ) preprocessing token, skipping intervening matched pairs of left and right parenthesis preprocessing tokens. Within the sequence of preprocessing tokens making up an invocation of a function-like macro, new-line is considered a normal white-space character.

like image 21
0decimal0 Avatar answered Oct 07 '22 17:10

0decimal0