clang-format:中断函数参数

标签 c clang-format

我想使用 clang-format 来生成 C 函数,例如:

void cfg_InitConfig
(
    cfg_Config_t* cfg,
    char*         name
)
{
    // TODO function
}

阅读手册后,我认为 clang-format 无法做到。
是否可以?

最佳答案

这是我当前打破函数参数以使用代码围栏而不是长行的最佳解决方案。我希望你能在这里找到有用的东西。

为了被围栏,有问题的代码必须比限制长,所以这里是它如何格式化更长的例子:

void cfg_InitConfig(cfg_Config_t *cfgxxxxxxxxxxxxxx,
                    char *namexxxxxxxxxxxxxxxxxxx) {
  // TODO function
}

! 符号表示这些行与代码围栏有关。
---
Language:      Cpp
BasedOnStyle:  Google

AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignOperands: false
AlignTrailingComments: false

# !
AllowAllParametersOfDeclarationOnNextLine: false

AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None

AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes

# !
BinPackArguments: false
BinPackParameters: false

ColumnLimit: 80
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
CompactNamespaces: false

IncludeBlocks: Preserve
IndentWidth: 2

DerivePointerAlignment: false
PointerAlignment: Right

SortIncludes: true
SortUsingDeclarations: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: true

关于clang-format:中断函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58995419/

相关文章:

c - 代码错误 : message queue not receiving the value

c - 为什么我在动态内存中得到错误的值?

c++ - 你如何在 Emacs、Ubuntu 上使用 Clang 格式?

c++ - CLion 中 clang 格式的 RawStringFormats 错误

c - 如果将 C 函数放在单独的文件中,会出现减速问题吗?

c - 让一个简单的 Makefile 工作

c - 如何通过防火墙沙箱和分析流量

c++ - clang-format:中断函数参数而不是函数限定符(noexcept)

c++ - Clang-Format:如何在 switch 语句中获取单行 case 语句

c++ - 仅当当前行溢出 clang 格式时才在新行上加括号