简体   繁体   English

铛格式指针 Alignment

[英]clang-format Pointer Alignment

I need use clang-format to take my source code in a style.我需要使用 clang-format 以某种风格获取我的源代码。 I try used the Linux kernel.clang-format, and take some modification in it.我尝试使用 Linux kernel.clang 格式,并对其进行一些修改。
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"?如何修改“int *n1”的.clang-format?

Make sure .clang-format is in your project directory, and make sure use确保.clang-format在您的项目目录中,并确保使用

clang-format -style=file yourCode.c

And your .clang-format should have a line like你的.clang-format应该有一行

---
PointerAlignment: Right

For more options, visit https://clang.llvm.org/docs/ClangFormatStyleOptions.html有关更多选项,请访问https://clang.llvm.org/docs/ClangFormatStyleOptions.html

I had found out the reason: The version of clang-format and LLVM is too low (6.0.0)!找到原因了:clang-format和LLVM的版本太低(6.0.0)!
If use 13.0.0 with the same.clang-format file, "PointerAlignment: Right" can give the good format!如果使用 13.0.0 和相同的.clang-format 文件,“PointerAlignment: Right”可以给出很好的格式!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM