Include Guards

Include guards are used to prevent a file, actually the contents of a file, from being included more than once.

Example, bigint.hpp:

#ifndef CS2_BIGINT_HPP
#define CS2_BIGINT_HPP

class bigint
{
  // ...
};

#endif

The header file above has an include guard. The ifndef is an if statement. The #endif is the end of the if body. The ndef in the if means not defined.

If CS2_BIGINT_HPP is defined as the preprocessor reads the file and the condition is false, then the if body is skipped.

If CS2_BIGINT_HPP is not defined as the preprocessor reads the file and the condition is true, then the body of the if is processed. The first thing that happens is CS2_BIGINT_HPP is is defined for the preprocessor. If another files includes this one again CS2_BIGINT_HPP is defined so the if condition will be false and the if body is skipped.

CS2_BIGINT_HPP is just a name and is usually derived from the header file's name.

All header files should have an include guard.

For some examples you can look at C++ header files in the directory /usr/include/c++/<version> (replace <version> with the most recent version number)