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

Normalize include guards to FS_<FILENAME>_H #3993

Merged
merged 1 commit into from
Mar 8, 2022

Conversation

ranisalt
Copy link
Member

@ranisalt ranisalt commented Mar 7, 2022

Pull Request Prelude

Changes Proposed

Let's have some standardization here. Prepended FS_ to every guard to avoid name clashes on common names.

We could alternatively use #pragma once instead, the code style suggests it but it was never really used.

@EPuncker EPuncker changed the title Normalize include guards to TFS_<FILENAME>_H Normalize include guards to FS_<FILENAME>_H Mar 8, 2022
@EPuncker EPuncker merged commit 6954775 into otland:master Mar 8, 2022
@Erza
Copy link
Contributor

Erza commented Mar 8, 2022

I like the pragma once idea, it's a compiler extension, but basically every single compiler supports it, and it's cleaner than these custom include guards.

https://en.wikipedia.org/wiki/Pragma_once#Portability

@ranisalt ranisalt deleted the normalize-include-guards branch March 8, 2022 14:51
@ranisalt
Copy link
Member Author

ranisalt commented Mar 8, 2022

Just to summarize:

Include guards

  • Defined in the standard 👍
  • Optimized by compilers 👍
  • Works with symlinks (that we should not use anyway) 🤷
  • Allows importing the same file from multiple places (useful for libraries, not for us) 🤷
  • Error prone (mismatched #ifndef/#define tokens, missing #endif) 👎
  • Prone to collision (i.e. two files using the same token) 👎

#pragma once

  • Optimized by definition 👍
  • Two lines less 🤷
  • Does not work with symlinks 🤷
  • Never collides, but allows importing twice from different places 🤷
  • Not standard (but available in every compiler that makes sense) 👎

EPuncker pushed a commit to EPuncker/forgottenserver that referenced this pull request May 23, 2023
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

Successfully merging this pull request may close these issues.

None yet

3 participants