No, this is not valid C++: it is ill-formed. There can be no tokens between the # endif
and the newline that terminates the preprocessing directive line.
If you want to restate the condition from the #if
directive, you can do so in a comment:
#endif // GUARD_H
However, this is really just redundant, especially for inclusion guards: if it's the last #endif
in a header file, it's almost certainly there to end the #ifdef
used at the top to prevent multiple inclusion, no?
In other places where you may have multiple nested levels of conditional directives, this might be useful, but even then it is often preferable to refactor the code to make it simpler or more straightforward.