c – Clang格式将语句体分成多行

c – Clang格式将语句体分成多行,第1张

概述我有以下.cpp文件: ////////////////////////////////////////////////////////////////////////////////void call_long_function_name(bool) {}void sf(bool) {}int main() { bool test = true; if (test) { call_ 我有以下.cpp文件:

////////////////////////////////////////////////////////////////////////////////voID call_long_function_name(bool) {}voID sf(bool) {}int main() {  bool test = true;  if (test) { call_function_name(test); }  if (test) { sf(test); }  return 0;}

(斜杠分隔80个字符).使用以下配置文件,clang-format建议:

////////////////////////////////////////////////////////////////////////////////voID call_long_function_name(bool) {}voID sf(bool) {}int main() {  bool test = true;  if (test) {     call_function_name(test);   }  if (test) {     sf(test);   }  return 0;}

甚至在文件中我允许简短的if语句适合单行.

>我设置了错误的选项吗?
>我可以使用哪些选项来最大限度地减少浪费的垂直空间?

Clang-format的.clang格式文件

BasedOnStyle: GoogleAccessModifIErOffset: -1Alignescapednewlinesleft: trueAlignTrailingComments: trueAllowAllParametersOfDeclarationOnNextline: trueAllowShortFunctionsOnASingleline: trueAllowShortIfStatementsOnASingleline: trueAllowShortLoopsOnASingleline: trueAlwaysBreakBeforeMultilinestrings: falseAlwaysBreakTemplateDeclarations: falseBinPackParameters: trueBreakBeforeBinaryOperators: trueBreakBeforeBraces: AttachBreakBeforeTernaryOperators: trueBreakConstructorInitializersBeforeComma: trueColumnlimit: 80ConstructorInitializerAllOnOnelineOrOnePerline: trueConstructorInitializerIndentWIDth: 2ContinuationIndentWIDth: 0Cpp11BracedListStyle: trueDerivePointerBinding: trueIndentCaseLabels: trueIndentFunctionDeclarationAfterType: trueIndentWIDth: 2MaxEmptylinesToKeep: 1namespaceIndentation: NonePointerBindsToType: trueSpaceAfterControlStatementKeyword: trueSpaceBeforeAssignmentoperators: trueSpaceInEmptyParentheses: falseSpacesBeforeTrailingComments: 2SpacesInCStyleCastParentheses: falseSpacesInParentheses: falseSpacesInAngles:  falseStandard: Cpp11TabWIDth: 2UseTab: Never
解决方法 较新版本的clang-format有一个额外的选项“AllowShortBlocksOnASingleline”,它控制着这种行为. 总结

以上是内存溢出为你收集整理的c – Clang格式将语句体分成多行全部内容,希望文章能够帮你解决c – Clang格式将语句体分成多行所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1220093.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存