castyle

Astyle with --remove-brackets and a macro


With the code:

#define MACRO(A,B) foo(A); bar(B)

if(true) {
    MACRO(A,B);
}

Astyle will remove the brackets around the macro call

if(true)
    MACRO(A,B);

Fortunately I found a solution. If I place the ; inside the macro, Astyle will understand it.

#define MACRO(A,B) foo(A); bar(B);

if(true) {
    MACRO(A,B)
}

Is it a good solution, is it a bug with Astyle or is my misunderstanding?


Solution

  • It's a bad style.

    If you absolutely must have multiple statements in macro, wrap them in do while loop (note the lack of semicolon at the end):

    #define MACRO(A,B) do { foo(A); bar(B); } while(0)