Home > OS >  clang-format Pointer Alignment
clang-format Pointer Alignment

Time:01-03

I need use clang-format to take my source code in a style. I try used the Linux kernel .clang-format, and take some modification in it.
But now one thing didn't come true:

/* This is clang-format result: */
struct one_name {
    int *   n1; /* Ummmm... */
    int     n2;
    double *p;
};

/* But I wanna this: */
struct one_name {
    int    *n1; /* The pointer is close to var name. */
    int     n2;
    double *p;
};

How to modify the .clang-format for the "int *n1"?

CodePudding user response:

Make sure .clang-format is in your project directory, and make sure use

clang-format -style=file yourCode.c

And your .clang-format should have a line like

---
PointerAlignment: Right

For more options, visit https://clang.llvm.org/docs/ClangFormatStyleOptions.html

CodePudding user response:

I had found out the reason: The version of clang-format and LLVM is too low (6.0.0)!
If use 13.0.0 with the same .clang-format file, "PointerAlignment: Right" can give the good format!

  • Related