“Multiple include guards may be useful for” what, exactly?

倾然丶 夕夏残阳落幕 提交于 2019-12-07 05:11:48

问题


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.)


回答1:


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++.



来源:https://stackoverflow.com/questions/33768477/multiple-include-guards-may-be-useful-for-what-exactly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!