Closed elfring closed 8 years ago
Perhaps it could be replaced with LUNA_AST
? I can do that if anyone would like.
How do you think about to make your include guards not only standard-compliant but also really unique by appending a kind of UUID?
Solution: don't use include guards. Use
#pragma once
instead.
@elfring using a random UUID for include guards isn't a very good idea. Conforming to a good naming scheme is.
@haneefmubarak Pragma once isn't standardized, and thus isn't guaranteed to be supported by every platform and compiler. Pragma once is used heavily on windows, but elsewhere you should stick with the standard.
@TheHydroImpulse I've actually never touched a windows system in terms of code, tbh. I do all of my work on and for Linux and OSX, and on both systems, whether using Clang or GCC, #pragma once
is all I use and it works without fail.
@haneefmubarak Just because it works doesn't mean you should use it. If you want to write standard C, use include guards.
Sometimes, you should use it, especially when it is well supported across all of the normal compilers.
http://stackoverflow.com/questions/1143936/pragma-once-vs-include-guards
If you want to write standard C, use include guards.
Most projects (especially open source projects) tend to use include guards because they're standardized.
And if you're doing embedded stuff, include guards are the way to go period. You don't always get the fancy features of modern C compilers.
Thankfully, we're developing for full systems and not AVRs or MSPs. Using the "fancy features of modern C compilers" means less mess, less chances of screwing something up, and less ugly guards, all at no cost.
If you want to write standard C, use include guards.
i.e., if you use #pragma once
, you're not writing standard C. Is that a bad thing? Maybe, or maybe not.
It's really a non-issue for your projects. But it certainly can be for other people's. Many popular open source C projects use standardized stuff, so they can be advertised as ANSI C and the like.
Here's a little something: it works perfectly fine with virtually all of the common compilers: GCC (properly since 2004 with GCC 3.4), Comeau, Clang, Intel, and Microsoft.
So other than being pedantic, there really isn't a reason not to use it, especially given the benefits it has, such as only being a one liner and not having to worry about naming schemes.
Further reading: http://teknicool.tumblr.com/post/19908569863/pragma-once-is-better-than-include-guards
I vote for something like LUNA_AST_H
Thanks for your improvement of affected include guards.
I would like to point out that identifiers like "
__LUNA_AST__
" and "__LUNA_TOKEN__
" do not fit to the expected naming convention of the C language standard. Would you like to adjust your selection for unique names?