You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置clang-format使宏定义的函数声明保持逐行显示

How to make clang-format put each DECL_DigOut macro call on its own line

Alright, I've got you covered here. The key is to tell clang-format that your DECL_DigOut macro should be treated as a standalone statement—this way, it'll automatically break each invocation onto its own line.

Here's how to do it:

  1. Update your .clang-format configuration
    Add the StatementMacros option to your config file, and include DECL_DigOut in the list. This tells clang-format to treat calls to this macro as individual statements, just like regular function calls or variable declarations.

    Example .clang-format snippet:

    # Other existing config options...
    StatementMacros:
      - DECL_DigOut
    
  2. Run clang-format again
    With this change, your problematic line of consecutive DECL_DigOut calls will be formatted to:

    DECL_DigOut(LED0, 4, 23, 0)
    DECL_DigOut(LED1, 4, 25, 0)
    DECL_DigOut(MAIN_HW0, 3, 14, 0)
    DECL_DigOut(MAIN_HW1, 3, 15, 0)
    DECL_DigOut(MAIN_HW2, 3, 16, 0)
    

Why this works

The StatementMacros list identifies macros that act as statements (even if they don't end with a semicolon). Clang-format will then apply statement-level formatting rules to them, including breaking each invocation onto a new line instead of keeping them all in one line.

If you have other similar macros (like DECL_GPO if you ever call it directly), you can add those to the StatementMacros list too to get the same behavior.

内容的提问来源于stack exchange,提问作者mastupristi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 05:47:28