Tempoz
Tempoz

Reputation: 21

How to clang-format this style of function definition

I would like to format my C code to a specific style of function definition like so:

foo.c (where "Arg" is a type/struct)

Example1:

void *
foo(
    const Arg *arg1 /**< my arg */
)
{
...
}

Example2

void *
foo(
    const Arg *arg1, /**< my arg */
    const Arg *arg2  /**< my arg2 */
)
{
...
}
  1. Break after return type (AlwaysBreakAfterDefinitionReturnType) - this works
  2. Break after name of function+open parens
  3. Each argument on a new line, indented
  4. closing parens on new line, un-indented

I've tried many combinations of parameters without success... any tips?

Upvotes: 0

Views: 542

Answers (1)

Lee Daniel Crocker
Lee Daniel Crocker

Reputation: 13171

I don't see how to do it with clang-format, but indent can come pretty close:

indent -i4 -cd24 -blf -bfda file.c

(except for that closing paren--not sure how to do that).

Upvotes: 1

Related Questions