在clang-format中对函数声明进行对齐

4

我在函数声明对齐方面遇到了问题。

考虑以下代码:

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以避免破坏这样的对齐方式也很有趣。 - mch
1个回答

4

虽然没有针对函数特定的选项,但有一个名为AlignConsecutiveDeclarations的选项,如果设置为true,则可以使连续的声明对齐。

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

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


很抱歉,似乎这些选项无法与clang-format-3.8一起使用,但是使用clang-format-6.0似乎完全可以。 - takladev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接