【问题标题】:How to prevent to break line in C at the end of for loop before ;如何防止在 for 循环结束之前在 C 中换行;
【发布时间】:2021-01-08 17:24:41
【问题描述】:

其实我的选择是:"C_Cpp.clang_format_fallbackStyle": "{ BreakBeforeBraces: Linux, IndentWidth: 4, ColumnLimit: 80, UseTab: Never, SortIncludes: false, AlignAfterOpenBracket: DontAlign }"

我有:

for (int i = 0; i < 5; i++)
    ;

我想要:

for (int i = 0; i < 5; i++);

【问题讨论】:

  • 第一个更清楚地表明空循环不是错误。如果是这样,它更容易吸引注意力。
  • 其实clang其实对第二种形式给出了警告,建议使用第一种形式。
  • @AdrianMole 是否也对第一个版本发出警告?
  • @WeatherVane 不。我想这就是它建议的原因。
  • 所以 clang 是在警告代码排版风格,而不是它的功能?

标签: c++ c visual-studio-code formatter


【解决方案1】:

这是一个已知问题,它会发出警告。唯一的办法就是这样写:

for (int i = 0; i < 5; i++) {}

【讨论】:

  • 这样写会大大更清楚。好的格式化程序/clang。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多