Hello everybody,

While reading C++, I have been looking into iostream header file to understand a bit more about header file organization. I am not able to understand much of the code in there.
For example the header starts with #ifndef _GLIBCXX_IOSTREAM. Does this check whether _GLIBCXX_IOSTREAM has been defined or not? If so then who is supposed to use this variable _GLIBCXX_IOSTREAM? I know it is not a good question but I am kind of curious.

Recommended Answers

All 6 Replies

Any line that starts with '#' is a "preprocessor directive". This particular one sounds like what is called a "header guard" or an "inclusion guard". It should be immediately followed by something along the lines of


. At the end of the file, there should also be a statement similar to this:

#endif /* _GLIBCXX_IOSTREAM */

This statement ends the statement block created by the #ifndef.

The #ifndef statement checks to see "if _GLIBCXX_IOSTREAM is NOT defined". If it finds that it is NOT defined, it returns true and executes the statements contained within its statement block. The next statement, #defines _GLIBCXX_IOSTREAM. As a result, _GLIBCXX_IOSTREAM now is defined. This causes #ifndef _GLIBCXX_IOSTREAM to come false if <iostream> is #included again so that it doesn't double up the #include. Here is more C++ - Specific preprocessor information.

This combination of statements is used to prevent the header being included in the code more than once which can cause compilation and linking issues.

Hello Fbody,

Thanks for the reply. Now I think I can understand what this means. _GLIBCXX_IOSTREAM is just a flag name for use in the header guard and the name has no other significance. PLease correct me if I am wrong.

That's essentially correct. It's actually what's called a "macro". It checks to see if the macro already exists. If it doesn't, the #define creates the macro.

These types of macros simply exist, and make compiling easier. They really are of no other use within your program.

Many thanks :)

what is 1(one) at the end of #define _GLIBCXX_IOSTREAM 1.????

what is the 1(one) use of this????

what is 1(one) at the end of #define _GLIBCXX_IOSTREAM 1.????

what is the 1(one) use of this????

Did you even read the thread? It's all laid out for you right in the thread. The "constant" _GLIBCXX_IOSTREAM has no use in the program other than to act as a header guard. You would not use it any where else.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.