[go: up one dir, main page]

Skip to content

Indents in multi-line pre-processor definitions

Consider a macro definition like:

#define MACRO_INIT(a, b, c, c1, c2, d, e) \
{                               \
    .a = a,  /* comment */      \
    .b = b,  /* comment */      \
    .c =     /* comment */      \
    {                           \
        .c1 = c1, /* comment */ \
        .c2 = c2  /* comment */ \
    },                          \
    .d = d,                     \
    .e = e                      \
}

When run through AStyle with --indent-preproc-define, the output looks like:

#define MACRO_INIT(a, b, c, c1, c2, d, e) \
    {                               \
        .a = a,  /* comment */      \
        .b = b,  /* comment */      \
        .c =     /* comment */      \
        {                           \
                                    .c1 = c1, /* comment */ \
                                    .c2 = c2  /* comment */ \
        },                          \
        .d = d,                     \
        .e = e                      \
    }

Notice how the .c1 and .c2 initialisers are indented to align the the \ line continuation character.

The comments in the example above are not the cause of the bad formatting, but I added them just to illustrate why the \ characters might be indented quite far in the first place.