Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treewide: move closing part of header guard to end of file #20905

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mguetschow
Copy link
Contributor

Contribution description

While reviewing #20865 (comment), I noticed that in many cases, the closing #endif of the header guard is not the last line in the file, leading to clang-format not recognizing it as a header guard. @maribu mentioned that this could also hinder some preprocessor optimations.

To produce the changes in this PR, I used the following search-replace pattern in VSCode: (#endif .*_H \*/)\n(/\*\* @\} \*/) and $2\n$1.

As a result, the preprocessor directives and doxygen groupings are not properly nested anymore, but at least to my tests, that didn't cause any harm. In general I'd say that it would make sense to have the header guard directly after the copyright and before the documentation, but that's probably something for another time.

Testing procedure

Quick glance a the changes. CI should pass and documentation should not look different (or be missing stuff).

Issues/PRs references

Noticed while reviewing #20865

@github-actions github-actions bot added Platform: native Platform: This PR/issue effects the native platform Platform: MSP Platform: This PR/issue effects MSP-based platforms Platform: ARM Platform: This PR/issue effects ARM-based platforms Area: network Area: Networking Area: tests Area: tests and testing framework Area: core Area: RIOT kernel. Handle PRs marked with this with care! Area: pkg Area: External package ports Platform: AVR Platform: This PR/issue effects AVR-based platforms labels Oct 11, 2024
@github-actions github-actions bot added Area: drivers Area: Device drivers Area: BLE Area: Bluetooth Low Energy support Area: timers Area: timer subsystems Area: tools Area: Supplementary tools Area: arduino API Area: Arduino wrapper API Area: LoRa Area: LoRa radio support Area: boards Area: Board ports Area: SAUL Area: Sensor/Actuator Uber Layer Area: OTA Area: Over-the-air updates Platform: ESP Platform: This PR/issue effects ESP-based platforms Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms Area: CoAP Area: Constrained Application Protocol implementations Area: cpu Area: CPU/MCU ports Area: USB Area: Universal Serial Bus Area: sys Area: System Area: examples Area: Example Applications labels Oct 11, 2024
/** @} */
#endif /* GPIO_PARAMS_H */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here specifically the @{ and the @} would now be unbalanced, as one of them is within and the other outside of the part covered by the include guard. I'm nit sure if I am just pedantic, or if this really could cause issues.

I think we wouod be better off with #pragma once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, as mentioned in the initial message, that's the case everywhere.

I think we wouod be better off with #pragma once.

I tend to agree. Let's maybe discuss #pragma once and the required coding convention changes next friday (I've already added it to the agenda).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second this. This unbalance was the first thing to come to my mind, upon opening this PR.

Also, I would be in support of a move to #pragma once. I moved to it years ago. It is just one less thing to think about with each new header. Reduction of cognitive load is always nice. And no worries of the include guard name colliding if you have headers of the same name in different locations, or when files get renamed, on top of all the other benefits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed the question of C language extensions in RIOT during the weekly today, and postponed it to the VMA: https://forum.riot-os.org/t/weekly-coordination-call-friday-at-10am-cet/3068/363

@mguetschow mguetschow marked this pull request as draft October 18, 2024 09:34
@mguetschow
Copy link
Contributor Author

I'll have a look at coccinelle to retain proper nesting between doxygen and include guards.

@miri64
Copy link
Member

miri64 commented Oct 18, 2024

I'll have a look at coccinelle to retain proper nesting between doxygen and include guards.

Try to test this with a few files first and see if it has any influence on the doxygen builds...

@mguetschow
Copy link
Contributor Author

@miri64 quoting myself from the PR description:

As a result, the preprocessor directives and doxygen groupings are not properly nested anymore, but at least to my tests, that didn't cause any harm. In general I'd say that it would make sense to have the header guard directly after the copyright and before the documentation, but that's probably something for another time.

@mguetschow
Copy link
Contributor Author

Unfortunately, it seems like matching against preprocessor directives and comments is not supported by coccinelle: https://coccinelle.gitlabpages.inria.fr/website/docs/main_grammar012.html

@miri64
Copy link
Member

miri64 commented Oct 18, 2024

(ノ-_-)ノ ミ ┴┴

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: arduino API Area: Arduino wrapper API Area: BLE Area: Bluetooth Low Energy support Area: boards Area: Board ports Area: CoAP Area: Constrained Application Protocol implementations Area: core Area: RIOT kernel. Handle PRs marked with this with care! Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers Area: examples Area: Example Applications Area: LoRa Area: LoRa radio support Area: network Area: Networking Area: OTA Area: Over-the-air updates Area: pkg Area: External package ports Area: SAUL Area: Sensor/Actuator Uber Layer Area: sys Area: System Area: tests Area: tests and testing framework Area: timers Area: timer subsystems Area: tools Area: Supplementary tools Area: USB Area: Universal Serial Bus Platform: ARM Platform: This PR/issue effects ARM-based platforms Platform: AVR Platform: This PR/issue effects AVR-based platforms Platform: ESP Platform: This PR/issue effects ESP-based platforms Platform: MSP Platform: This PR/issue effects MSP-based platforms Platform: native Platform: This PR/issue effects the native platform Platform: RISC-V Platform: This PR/issue effects RISC-V-based platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants