Itzik984
Itzik984

Reputation: 16764

Macro definition malformed for macro

I have the following macro which is supposed to get a struct CLEAR_ARG and set some values to it:

#define POLICY_ARG_SET((CLEAR_ARG), ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8) \
    CLEAR_ARG->arg1= ARG1 \
    CLEAR_ARG->arg2 = ARG2; \
    CLEAR_ARG->arg3 = ARG3; \
    CLEAR_ARG->arg4 = ARG4; \
    CLEAR_ARG->arg5 = ARG5; \
    CLEAR_ARG->arg6 = ARG6; \
    CLEAR_ARG->arg7 = ARG7; \
    CLEAR_ARG->arg8 = ARG8;

But I get macro definition malformed for macro warning for some reason.

I used the macro without the brackets over the (CLEAR_ARG), and set the struct with

POLICY_ARG_SET((&clear_arg),...)

but I don't want to always worry about the brackets. Why do I get this warning, and how can it be solved?

Upvotes: 2

Views: 2294

Answers (1)

Veger
Veger

Reputation: 37905

You have misplaced the parentheses. In the name and arguments you cannot use them, you need to use them in the definition (the part that gets expanded).

Change your macro to this and it should work:

#define POLICY_ARG_SET(CLEAR_ARG, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8) \
    (CLEAR_ARG)->arg1 = ARG1; \
    (CLEAR_ARG)->arg2 = ARG2; \
    (CLEAR_ARG)->arg3 = ARG3; \
    (CLEAR_ARG)->arg4 = ARG4; \
    (CLEAR_ARG)->arg5 = ARG5; \
    (CLEAR_ARG)->arg6 = ARG6; \
    (CLEAR_ARG)->arg7 = ARG7; \
    (CLEAR_ARG)->arg8 = ARG8;

Note, in your example (CLEAR_ARG)->arg1 = ARG1; is missing a semi-colon (;) as well

Upvotes: 7

Related Questions