0

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.

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by Fbody
0

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

#define _GLIBCXX_IOSTREAM 1

. 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.

Edited by Fbody: n/a

0

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.

0

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.

Edited by Fbody: n/a

-1

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

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

0

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.

Edited by Fbody: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.