Skip to content

Unify C++ source and header file extensions #44196

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

Open
stephanosio opened this issue Mar 25, 2022 · 10 comments
Open

Unify C++ source and header file extensions #44196

stephanosio opened this issue Mar 25, 2022 · 10 comments
Assignees
Labels
area: C++ RFC Request For Comments: want input from the community

Comments

@stephanosio
Copy link
Member

stephanosio commented Mar 25, 2022

Overview

Currently, we have different file extensions for the C++ source and header files in the Zephyr repository:

Source Files

Header Files

For the sake of consistency, the project should decide on and use only single extension each for the C++ source and header files.

Context

Widely-used conventions

C++ source Files: .cpp, .cxx, .cc, C
C++ header Files: .hpp, .hxx, .hh, h

From the perspective of the Standard C++ Foundation

Opinions

Amongst the "widely-used conventions" listed above, some to avoid are:

  • C (capital C) for source files
    • This will not play well with the operating systems that do not strictly enforce the case sensitiveness of the file names (e.g. Windows, macOS).
    • This is more prone to human errors than having alphabetically different names for the C++ source files and the C source files.
  • h for C++ header files
    • This provides no distinction between the C++ header files and the C header files.

Proposed Change

  • Use .cpp for C++ source files.
  • Use .hpp for C++ header files.
@stephanosio stephanosio added RFC Request For Comments: want input from the community area: C++ dev-review To be discussed in dev-review meeting labels Mar 25, 2022
@stephanosio
Copy link
Member Author

Please feel free to update this issue with more contexts and opinions.

@stephanosio
Copy link
Member Author

@tknapstad
Copy link

I would suggest the .hpp/.cpp standard adopted by the Boost libraries. Gcc and Clang will automatically recognize all alternatives, but at least the Arm Keil compiler requires an additional command line switch to recognize the source file as C++ code unless the filename extension is .cpp (see https://www.keil.com/support/man/docs/armcc/armcc_chr1359124195123.htm). I don't know if IAR has similar quirks (or if Zephyr supports/wants to support these toolchains) but I think that .hpp/.cpp are the most widely adopted C++ filename extensions.

@cfriedt
Copy link
Member

cfriedt commented Mar 25, 2022

.cpp / .hpp is fine with me, although the fact is, 3rd party code will likely be named .cpp / .h and we will need to deal with that as well (CMake handles this just fine).

@stephanosio
Copy link
Member Author

I also prefer .hpp/.cpp.

By the way, the scope of this is the files that are being committed to the main Zephyr repository (i.e. zephyrproject-rtos/zephyr) only. Third-party code in the modules can keep whatever convention their upstream repo uses.

@alexanderwachter
Copy link
Member

+1 for .cpp .hpp

@carlescufi
Copy link
Member

Another vote for .hpp/.cpp for files in the main zephyr tree, as mentioned by @stephanosio.

@ppryga-nordic
Copy link
Collaborator

In my experience .hpp/.cpp are most widely used. Let's use these.

@mkschreder
Copy link

I also vote for .hpp / .cpp.

Make sure that you also add a compliance check that fails all the others so we don't forget we made this decision.

@MaureenHelm MaureenHelm removed the dev-review To be discussed in dev-review meeting label Mar 31, 2022
yperess added a commit to yperess/zephyr that referenced this issue Apr 5, 2022
Rename all .cc files to .cpp (note that no .hh files were found).
Addresses zephyrproject-rtos#44196

Signed-off-by: Yuval Peress <[email protected]>
MaureenHelm pushed a commit that referenced this issue Apr 11, 2022
Rename all .cc files to .cpp (note that no .hh files were found).
Addresses #44196

Signed-off-by: Yuval Peress <[email protected]>
@stephanosio stephanosio mentioned this issue May 19, 2022
8 tasks
@stephanosio stephanosio self-assigned this Jan 26, 2023
@zephyrbot
Copy link
Collaborator

Hi @stephanosio,

This issue, marked as an RFC, was opened a while ago and did not get any traction. Please confirm the issue is correctly assigned and re-assign it otherwise.

Please take a moment to review if the issue is still relevant to the project. If it is, please provide feedback and direction on how to move forward. If it is not, has already been addressed, is a duplicate, or is no longer relevant, please close it with a short comment explaining the reason.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: C++ RFC Request For Comments: want input from the community
Projects
Status: No status
Development

No branches or pull requests

9 participants