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

Question: Where does the #include " " conding convention come from? #15522

Closed
kfessel opened this issue Nov 30, 2020 · 6 comments
Closed

Question: Where does the #include " " conding convention come from? #15522

kfessel opened this issue Nov 30, 2020 · 6 comments
Labels
Type: question The issue poses a question regarding usage of RIOT

Comments

@kfessel
Copy link
Contributor

kfessel commented Nov 30, 2020

Where does the #include coding convention come from?

Description

RIOT-OS has a coding convention of using #include " " for its RIOT System includes to differentiate them from #include < > which should be used for compiler includes only.

This seems special to me and at least to some other people PR in ndn-riot I tried to find the reasoning in the RIOT git history but i failed. In 7caf788 (14/11/2013) Ludwig Ortmann mentioned the coding convetion (maybe the first time). The Coding_Convetions .md file got added by @maribu at 25/10/2019 but somehow must have been there before.

As i wrote in the ndn PR at least Arduino and Zephy use < > for non compiler library includes.

Useful links

a blog post that did some digging through c standard
not very help full gcc manual
microsoft was a little more clear there are some words about parent includes that if they apply to gcc my lead to some difficult to explain behavior.

K&R 2 page 102 and 103

my 2 cent

Reading the blog-post mentioned above i get the C-Standard does not say anything to distinguish #include "" from #include <> (i also checked if newer or newer standards say something but the paragraph seems to be unchanged); K&R said something which the RIOT CC conflicts with.

quoting myself from the ndn PR:

K&R could have saved us from this discussion if they just had not defined the fallback case for " "

it would have been you know the path -> " "
compiler has to search -> < >

the fallback case for " " is what RIOT is using

@kfessel kfessel changed the title Question: Where does the #include conding convention come from? Question: Where does the #include " " conding convention come from? Nov 30, 2020
@kaspar030
Copy link
Contributor

Where does the #include coding convention come from?

Style. "foo.h" is "one of ours", whereas <foo.h> is "comes from the runtime/libc/whatever". That only goes upstream, we consider package headers as "ours".
The angle brackets form searches "preconfigured list of standard system directories". For RIOT being a library OS usually compiled to a baremetal target, that means toolchain provided include paths. Quote includes search paths added with -I before those. So using the quote form hints to the reader that "we don't expect this to be found in the toolchain include paths".

@miri64
Copy link
Member

miri64 commented Nov 30, 2020

The Coding_Convetions .md file got added by @maribu at 25/10/2019 but somehow must have been there before.

For reference, as the PR importing that .md indicates: the coding conventions where maintained in the Wiki before. Best way to track the history there is to check out the wiki via git (git clone [email protected]:RIOT-OS/RIOT.wiki.git and view the log of the Coding-conventions.md) there.

@kfessel
Copy link
Contributor Author

kfessel commented Nov 30, 2020

i just checked gcc does not apply what msvc does for the quoted form rule 2 (the parrent include) < this would be a problem
incl_test.zip

cd main
gcc -I ../inc1 -I ../inc2 main.c 

gcc for quoted -> the currents file directory -> the rest is like angel brackets
gcc for angel -> search -I include paths last added is first to be searched -> search compiler system includes

the <> form also searches -I first before compiler

@jeandudey jeandudey added the Type: question The issue poses a question regarding usage of RIOT label Mar 20, 2021
@MrKevinWeiss MrKevinWeiss added this to the Release 2021.07 milestone Jun 22, 2021
@MrKevinWeiss MrKevinWeiss removed this from the Release 2021.07 milestone Jul 15, 2021
@stale
Copy link

stale bot commented Mar 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added State: stale State: The issue / PR has no activity for >185 days and removed State: stale State: The issue / PR has no activity for >185 days labels Mar 2, 2022
@kfessel
Copy link
Contributor Author

kfessel commented Mar 2, 2022

... So using the quote form hints to the reader that "we don't expect this to be found in the toolchain include paths".

Most other projects use #include " " to indicate that the file is found right next to the file including and < > to indicat it is in the include path (not caring if it is in the libc or in (lib))

@maribu
Copy link
Member

maribu commented May 17, 2023

Question was answered --> closing this.

@maribu maribu closed this as completed May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: question The issue poses a question regarding usage of RIOT
Projects
None yet
Development

No branches or pull requests

6 participants