gpt4 book ai didi

c - 如何以 clang 格式包装结构初始值设定项?

转载 作者:行者123 更新时间:2023-12-03 16:18:41 25 4
gpt4 key购买 nike

在 clang-format 运行之前以这个例子为例:

struct ApplicationState app_state = {
.signal = {
.use_crash_handler = true,
.use_abort_handler = true,
},
.exit_code_on_error = {
.python = 0,
}
};

运行后,clang-format 应用如下:
struct ApplicationState app_state = {.signal =
{
.use_crash_handler = true,
.use_abort_handler = true,
},
.exit_code_on_error = {
.python = 0,
}};

有没有办法在大括号之后,结构成员之前添加换行符,这样它更像是第一个例子而不是第二个例子?

最佳答案

当前 clang-format没有一种有用的方法来控制它(从 11.0 版开始)。
虽然 BreakBeforeBinaryOperators: All确实强制包装(参见@eric-backus 的回答),它也会影响许多其他地方的格式,与结构声明无关。
但是,您可以通过使用尾随逗号来解决此问题。

前:

struct ApplicationState app_state = {.signal =
{
.use_crash_handler = true,
.use_abort_handler = true,
},
.exit_code_on_error = {
.python = 0,
}};
后:

struct ApplicationState app_state = {
.signal = {
.use_crash_handler = true,
.use_abort_handler = true,
},
.exit_code_on_error = {
.python = 0,
},
};
/* ^ notice trailing comma on the second last line! */

关于c - 如何以 clang 格式包装结构初始值设定项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47409797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com