gccheader-filesinclude-guards

"Multiple include guards may be useful for" what, exactly?


I've been playing around with the -H option of gcc, which prints out information about direct and indirect includes in C and C++ compilation (relevant section of the gcc manual).

As part of the output there's a section "Multiple include guards may be useful for:", which lists a number of project and system headers.

What does this mean, how is this list determined, and why is it saying "Multiple" include guards may be useful?

(I'm familiar with the general concept of include guards, and why one would want to use them - I'm looking for details about this message in particular, and what it means for my project.)


Solution

  • In this case, "multiple" modifies "includes" -- not "guards". So "include guards" and "multiple include guards" are the same thing. That is, they guard against multiple includes of the same file.

    The list is made by something approximately like this: first, all files are considered for the list. However, the main file is excluded; and files that have an include guard; files that are opened with #import; and files that have #pragma once.

    Reasons to use guards are that they make a header file idempotent, and they can reduce compilation time. IMO they are a best practice for C and C++.