Last active
October 27, 2015 09:23
-
-
Save WoodyWoodsta/44b5d232375f0dfb3d76 to your computer and use it in GitHub Desktop.
Multiple inclusion guard tactic for C explained
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** To prevent your code having multiply included header files, | |
* and hence possibly multiply declared functions and variables, | |
* the following tactic is used in the file to be included which will | |
* prevent the code from being compiled more than once. | |
*/ | |
// The "ifndef" combined with the matching "endif" directives serve as a pre-processor | |
// "if not defined" statement, where the code between these two directives will only | |
// Be compiled if, in this case, the symbol "NAME_OF_HEADER_FILE_H" has not been defined. | |
#ifndef NAME_OF_HEADER_FILE_H | |
#define NAME_OF_HEADER_FILE_H // This defines the symbol, which means that the "ifndef" directive in all | |
// other multiply included files will evaluate to false, and the code within | |
// it and the "endif" will not be compiled! Problem solved. | |
// == Header contents == | |
#endif // This is the matching directive that encloses the code to be either compiled or ignored | |
// NOTE: that this is not the only use of the #define directive. There are a huge amount of other use cases! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment