I currently do the following and the compiler (MSVC2008 / as well as 2010) doesn't complain about it but I'm not sure if it's a bad idea or not:
#ifndef FOO_H_
#define FOO_H_
// note, FOO_H_ is not a comment:
#endif FOO_H_
I used to always write it as #endif // FOO_H_
but I caught myself not doing that today and thought it was strange because apparently I've not done the comment method for a while.
Is this bad practice that I should go back through all of my headers and fix (it's a cross-platform application) or is it okay to leave it the way it is?
It is not ok, it is not valid, AFAIK. Many compilers ignore the extra text after the #endif
though and often they warn about it. You should add the //
to make it a comment.
Strictly speaking (according to the grammar in the standard) no tokens are allowed following the #endif
directive on the same line (comments are OK since they get removed at an earlier phase of translation than the preprocessing directives - phase 3 vs. 4).
However, MSVC seems to allow it - I wouldn't go on a quest to fix these (since they aren't causing a problem), but would probably make a mental note to fix them as you modify the headers that have them.
Of course, if your other supported compilers issue diagnostics about them it's probably more urgent to fix them.
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