Programming: Making Sure Library is Compiled only Once (#ifndef...#endif)

All libraries (header files .h) that are created for c or c++ programs must have code in them to make sure they are not compiled more than once. The use of #ifndef #define and #endif is used for this. The #ifndef means if not defined. If a define is in the top portion of the library file to demarkate the file by a special name, then an ifndef can be used to make sure the code in that library is omitted if the define was alreay seen by the compiler.



Usage: #ifndef name #define name library code ... #endif
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.