本文介绍了“多个包括警卫可能对于”究竟是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用gcc的-H选项,它打印出有关C和C ++编译中直接和间接包含的信息()。



作为输出的一部分,有一个部分多个包含守护程序可能对以下用途:,其中列出了许多项目和系统标头。
$ b

这是什么意思,这个列表是如何确定的,为什么它说Multiple包含守卫可能有用?



(我熟悉包括守卫的一般概念,为什么要使用它们 - 我正在寻找关于此消息的详细信息,以及它对我的项目意味着什么。)

解决方案

在这种情况下,multiple会修改includes - 而不是guard。所以包括警卫和多个包括警卫是一回事。也就是说,他们会警惕多个包含同一个文件。



这个列表大概是这样做的:首先,列表中的所有文件都被考虑在内。但是,主文件被排除在外;和包含警卫的文件;使用 #import 打开的文件;以及具有 #pragma once 的文件。



使用警卫的原因是它们使头文件具有幂等性,并且他们可以缩短编译时间。 IMO是C和C ++的最佳实践。


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

解决方案

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

这篇关于“多个包括警卫可能对于”究竟是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 02:01