Click here to Skip to main content
15,887,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to ask a very basic question. Can anyone explain the use of these statements in the same file? What does these statements signify when written together?

C++
#ifndef ABC_H
#define ABC_H
//code
#endif 
Posted

This is known as inclusion guard. In C/C++ we include header files. It is possible that one header file may be included in server other header files. Suppose you have two such header files, which includes say "File.h", your preprocessor expands File.h twice. To avoid this we use inclusion guards.

For more details see this[^]
 
Share this answer
 
Comments
Member 8576081 4-Apr-12 7:28am    
Thanx a lot for such a quick response...
[no name] 4-Apr-12 7:48am    
Thx
These are 'inclusion guards'.
See http://en.wikipedia.org/wiki/Include_guard[^]
Basically, they let you include the same header more than once in a module, without generating an error.

Hope this helps,

Pablo.
 
Share this answer
 
Comments
Member 8576081 4-Apr-12 7:29am    
Thanx Pablo!

The code between #ifndef ABC_H and #endif is compiled only when ABC_H isn't defined.


The #define ABC_H line, defines the ABC_H identifier.


This combination is used often, in order to ensure that a header file is included only one time. At the first time that the compiler enters to the file, the ABC_H identifier isn't defined, so the content of the file is included (and the ABC_H identifier is defined). At the next time that the compiler enters to the file, the ABC_H identifier is already defined...

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900