【问题标题】:aligning function declarations in clang-format以 clang 格式对齐函数声明
【发布时间】:2019-05-02 12:17:15
【问题描述】:

我对函数声明对齐有疑问。

考虑:

RplInstanceS* RplGetInstance(inst_t instID, uint8_t createFlag);
RplDagS* RplGetDag(RplInstanceS* inst, RplAddrS* dagID, uint8_t createFlag);
void RplFreeInstance(RplInstanceS* inst, uint8_t forced);
void ResetDioTrickle(RplDagS* dag);
RplDagS* GetNextInuseDag(int* state);
void    RplFreeAllInstances(void);
uint8_t CountAllInstances(void);
uint8_t StartAllInstances(void);

我希望有一个 clang-format 选项可以将其转换为:

RplInstanceS* RplGetInstance(inst_t instID, uint8_t createFlag);
RplDagS*      RplGetDag(RplInstanceS* inst, RplAddrS* dagID, uint8_t createFlag);
void          RplFreeInstance(RplInstanceS* inst, uint8_t forced);
void          ResetDioTrickle(RplDagS* dag);
RplDagS*      GetNextInuseDag(int* state);
void          RplFreeAllInstances(void);
uint8_t       CountAllInstances(void);
uint8_t       StartAllInstances(void);

【问题讨论】:

  • 好问题,如何设置 clang-format 以不破坏这种对齐方式也会很有趣。

标签: c++ c clang-format


【解决方案1】:

没有特定于函数的选项,但有 AlignConsecutiveDeclarations 选项,如果设置为 true,则对齐连续声明。

这可以与PointerAlignment 选项一起使用,其值设置为PAS_Left(在配置中:左),这将使指针向左对齐。

这两个选项的组合应该可以满足您的需求。

【讨论】:

  • 抱歉,这些选项似乎不适用于 clang-format-3.8,但使用 clang-format-6.0 似乎可以正常工作。
猜你喜欢
  • 1970-01-01
  • 2015-12-17
  • 1970-01-01
  • 2016-11-21
  • 1970-01-01
  • 2012-07-17
  • 1970-01-01
  • 1970-01-01
  • 2016-11-18
相关资源
最近更新 更多