Skip to content

docs: describe where a macro comment goes - #11973

Merged
Rbb666 merged 1 commit into
RT-Thread:masterfrom
Yunlk:docs/macro-comment-position
Nov 3, 2026
Merged

Rbb666 merged 1 commit into
RT-Thread:masterfrom
Yunlk:docs/macro-comment-position

Conversation

@Yunlk

@Yunlk Yunlk commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

闭合 #10097。

现有规范只说了"语句注释只能写在上方或右方"(coding_style_cn.md:116),没有说明宏该选哪一种、依据是什么,于是同一份代码里两种写法并存,新人无从判断。

先查了仓库现状,规则其实是自洽的,只是一直没写下来:

  • include/ 下 135 处宏注释用行尾 /**<
  • 函数式宏则用上方块注释 + @def

你的解决方案是什么 (what is your solution)

在中英文两份 coding_style 的第 8 节各补一节「宏注释」,给出判断标准与真实示例。

判断依据是"需要多少说明",不是行长——这一点我一开始写错了,查了数据才改过来:

统计 include/ 下 135 处行尾宏注释,其中 87 处(64.4%)超过 80 列,例如 kerrno.h:24 是 95 列。也就是说成组的常量宏是故意保持列对齐、接受超长的;如果按"超 80 列就移到上方"来写,会和现有大半个代码库冲突。

所以最终写的是:

  • 一条注释能说清 → 放行尾(简单常量宏,成组时优先纵向对齐)
  • 需要一段话才能说清 → 放上方 + @def(带参数的宏,要描述入参/展开结果/使用限制)

两份文档都用了仓库里真实存在的例子(include/klibc/kerrno.h:23-25 的错误码组、include/rtdef.h:248-257 的 RT_ALIGN),不是编的示例。

另外补了一条实践上的差别:开启 MACRO_EXPANSION 后,行尾 /**< 是挂在宏展开点上的,同一宏多处展开时注释位置可能出乎意料;上方块注释始终绑定定义处。因此频繁展开的宏优先用上方块注释。

请提供验证的bsp和config (provide the config and bsp)

纯文档改动,不涉及编译。文中所有示例均逐字核对过源文件:

  • include/klibc/kerrno.h:23-25 —— 三行错误码,行尾 /**<
  • include/rtdef.h:248-257 —— RT_ALIGN 的 /** + @def 块,该行 81 列

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用clang-format 源码格式化工具确保格式符合RT-Thread代码规范 This PR has been formatted with clang-format and complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

Closes RT-Thread#10097.

The coding style only said that comments go above or to the right of the code,
without saying which applies to a macro. The repository already follows a
consistent rule, it just was not written down:

- 135 macro comments in include/ use a trailing /**<
- a further set of function-like macros use a /** block above the definition with

@def

The rule is about how much explanation the macro needs, not about line length.
A single line goes trailing; a paragraph goes above. That distinction matters
because the column-aligned groups of constant macros routinely exceed 80 columns
once the comment is appended - 87 of those 135 lines (64%) are longer than 80
columns, and shortening them would break the alignment that makes them readable.

Both language versions get the same section, with the real examples from
include/klibc/kerrno.h and include/rtdef.h, plus a note that with
MACRO_EXPANSION enabled a trailing /**< follows the expansion site while a block
comment stays with the definition - which is why frequently expanded macros
should use the block form.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: documentation

Reviewers: @CXSforHPU @GorrayLi @lianux-mm

Changed Files (Click to expand)
  • documentation/7.contribution/coding_style_cn.md
  • documentation/7.contribution/coding_style_en.md

📊 Current Review Status (Last Updated: 2026-11-02 16:06 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@github-actions github-actions Bot added the Doc This PR/issue related with documents label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • Use workflow from 保持默认分支(通常为 master)
    Keep the default branch (usually master) in Use workflow from
  • 在 branch 输入框填写 PR 分支 docs/macro-comment-position
    Enter PR branch docs/macro-comment-position in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 docs/macro-comment-position 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the docs/macro-comment-position branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@Rbb666
Rbb666 merged commit e0aa4ce into RT-Thread:master Nov 3, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Doc This PR/issue related with documents

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants