-1

Why inside myheader.h, we write:

#ifndef MYHEADER_H
#define MYHEADER_H
...
#endif

Since, Identifiers are case-sensitive (lowercase and uppercase letters are distinct), and every character is significant. How the above is valid? It should be

#ifndef myheader.h
#define myheader.h
...
#endif

What is the purpose of the underscores? What if I have 2 separate header files with names: MyHeader.h and myheader.h, How does the preprocessor distinguish between these?

1

1 Answer 1

1

The leading underscore followed by uppercase indicates that it's either a name defined by the C++ implementation, because this form is reserved for the implementation, or it's a name defined by someone who has seen this in system headers and just copy-cat adopted it without understanding it.

Sign up to request clarification or add additional context in comments.

2 Comments

So for user defined header files, we should not include the leading underscores?
@Nikhil: Right. Also avoid other reserved forms, which are (1) two successive underscores anywhere, or, (2) leading underscore in a name in the global namespace.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.