In eclipse, when a c++ class is created, .h file's auto-generated with guard XXXX_H_. In my limited, little experience, the guard is always be in the form of XXXX_H without the trailing _.
So, I'm just curious and wondering why the _ is over there.
Thanks in advance.
The trailing _ might be added to avoid collision with user-defined identifiers. For example, you might have a header file named get.h and at the same time you can conceivably have your own macro (or variable, or function) named GET_H. So, using GET_H for include guard in get.h would easily lead to problems.
The standard library header files might use a leading _ to name its internal macros for the very same purpose - to avoid name collision with user-defined identifiers. For that reason, the language specification explicitly prohibits user-defined identifiers that begin with _ and a capital letter. And for the very same reason, the leading _ cannot be used in the names of include guards.
So, Eclipse decided to use a trailing _ for the very same purpose. It provides a reasonable level of protection from name collisions and does not violate the requirements of language specification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With