user3624683
user3624683

Reputation: 21

Why are c++ Header Guards names in capital and with underscore?

I noticed that .h files have their name capitalized and uses underscore for header guards....why is that?

for example take "doThat.h"

the header guard would be:

#ifndef DO_THAT_H
#define DO_THAT_H

why is it capitalized and underscored like that? even if in the main.cpp you only type #include "doThat.h" to use the file?? There is some real programing reason to this? why not just type :

#ifndef doThat.h
#define doThat.h

Upvotes: 2

Views: 2144

Answers (2)

Remy Lebeau
Remy Lebeau

Reputation: 595971

It is just a naming convention, not a hard rule. It is not uncommon to see DOTHAT_H or DOTHATH or DoThatH instead, for instance. What is important is that the #define use a unique identifier that does not clash with other files. Some variation of the calling filename is typically used.

Upvotes: 2

C. K. Young
C. K. Young

Reputation: 223003

Preprocessor definitions have to use valid identifiers. Dots are not valid in identifiers.

There is also a convention that preprocessor definitions (especially preprocessor macros) use all-uppercase names, to distinguish them from non-preprocessor identifiers. (It's not a hard-and-fast rule, though; for example, errno is usually a macro, but it's not uppercase.)

Upvotes: 5

Related Questions