Multiple successive declarations/definitions on same indentation level

250 views Asked by At

I'm trying to clean up my C codebase using clang-format (version 3.8.) on Ubuntu 14.04. As a requirement I need clang-format to maintain (or better enforce) the indentation of multiple successive declarations/definitions. For example:

void foo() 
{
    int        a;
    float      b;
    myLongType c;
}

After running clang-format I get the following output:

void foo() 
{
    int a;
    float b;
    myLongType c;
}

Is there an option that I'm not aware of to keep/enforce this formatting?

If this is not possible, is it possible to extend the functionality of clang-format locally (as it is with clang-tidy?) or do I have to open a feature request?

I know that this kind of formatting is mostly used in C code bases, and although the help message states "A tool to format C/C++/Java/...", all the options seem to be mainly targeted to C++.

1

There are 1 answers

1
datosh On BEST ANSWER

Just overread the correct option. From Clang Format Options website:

AlignConsecutiveDeclarations (bool):

If true, aligns consecutive declarations.

This will align the declaration names of consecutive lines. This will result in formattings like

int         aaaa = 12;
float       b = 23;
std::string ccc = 23;