error: #29: expected an expression in C
Solution 1
The braces and semicolon in your macro are wrong. Use:
#define READ_TAMPER_PIN() ((FIO2PIN & PIN_TAMPER) >> 12)
Solution 2
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.
YMJ
Updated on July 05, 2022Comments
-
YMJ almost 2 years
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??