【问题标题】:How to align a designated initializer in C99 with clang-format?如何将 C99 中的指定初始化程序与 clang 格式对齐?
【发布时间】:2018-04-06 09:28:54
【问题描述】:

我正在使用 clang-format 4.0.0 来调整我的个人项目。 我正在为 clang-format 使用以下配置。

Language:        Cpp
BreakBeforeBraces: Allman
ColumnLimit:     120
TabWidth:        4
IndentWidth:     4
UseTab:          ForContinuationAndIndentation

下面的示例代码使用上面的配置对齐。

struct test
{
    int a;
    int b;
    int c;
};

struct test T = {
    .a = 1, .b = 2, .c = 3,
};

有没有办法像下面显示的那样对齐初始化部分。 基本上我正在寻找一种方法将所有初始化程序放在单独的行中。

struct test T =
{
    .a = 1,
    .b = 2,
    .c = 3,
};

【问题讨论】:

    标签: clang-format


    【解决方案1】:

    使用 clang-format 6.0.0,格式是您所要求的。事实上,似乎不再有任何方法可以获得您不喜欢的单行格式。

    【讨论】:

    • 好像又回到了clang 10 ... :(
    • 嗯。使用zed0.co.uk/clang-format-configurator,我在 4.0.1 之后的任何版本的 clang-format 上都看不到它。
    • 我错过了最后一个结构条目后的逗号。似乎有必要单独打破一行上的每个结构条目......
    猜你喜欢
    • 2021-05-15
    • 2023-03-12
    • 2013-05-29
    • 2018-05-04
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 2021-01-02
    相关资源
    最近更新 更多