英文:
clang-format: designated initializer: One member per line
问题
我有一个在C语言中的结构体:
struct A {
int a;
int b;
int c;
}
当初始化结构体时,clang-format会将代码格式化如下:
struct A name = {.a = 1, .b = 2, .c = 3};
如何告诉clang-format将结构体的每个成员放在单独的行上,像这样:
struct A name = {
.a = 1,
.b = 2,
.c = 3
};
英文:
I have a struct in C:
struct A {
int a;
int b;
int c;
}
When initializing the struct clang-format reformats the code as follows:
struct A name = {.a = 1, .b = 2, .c = 3};
How can I tell clang-format to put any member in its own line? Like so:
struct A name = {
.a = 1,
.b = 2,
.c = 3
};
答案1
得分: 0
在这个问题中,添加一个尾随逗号应该可以解决这个问题。
struct A name = {
.a = 1,
.b = 2,
.c = 3, // <-- 这个尾随逗号是必需的
};
英文:
Adding a trailing comma should fix this problem.
struct A name = {
.a = 1,
.b = 2,
.c = 3, // <-- this trailing comma is needed
};
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论