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

don't use inclusion guards when including header files #20

Closed
jeremyhannon opened this issue Sep 19, 2017 · 1 comment
Closed

don't use inclusion guards when including header files #20

jeremyhannon opened this issue Sep 19, 2017 · 1 comment

Comments

@jeremyhannon
Copy link
Contributor

inclusion guards (sentinels) should not be used outside of the header in which they are defined. And I think it's alright/good/expected that a header file could be #included multiple times in a chain of headers. That's why we have inclusion guards inside every header file to prevent actual multiple inclusion of the header contents. So I don't think the library should include code like the following.

#ifndef __SAFE_LIB_H__
  #include "safe_lib.h"
#endif

It should simply be #include "safe_lib.h" Inside the header file we already have:

#ifndef __SAFE_LIB_H__
#define __SAFE_LIB_H__
... file contents
#endif /* __SAFE_LIB_H__ */

Are you receiving a warning somewhere when you write the code like this? Maybe a warning that needs to be tuned/silenced?

@rurban
Copy link
Owner

rurban commented Sep 21, 2017

Ah, that's right.
I was playing with mingw support that time, which needed it, and obviously wrapped my head 360˚.

Needs to be fixed, as you suggested.

rurban added a commit that referenced this issue Sep 25, 2017
Don't use inclusion guards when including header files.
Just include them vice-versa, simple is better.
@rurban rurban closed this as completed in 234f3b0 Sep 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants