include - #pragma once 与 #if !defined MYHEADER_INCLUDED_

标签 include c-preprocessor

这个问题在这里已经有了答案:




9年前关闭。




Possible Duplicate:
#pragma once vs include guards?



使用 #pragma once 有什么区别(在性能、可用​​性和功能方面)和 #if !defined MYHEADER_INCLUDED_结构体?或者两者有什么区别?

最佳答案

维基百科有你所有的答案,很容易找到

From the article

In the C and C++ programming languages, #pragma once is a non-standard but widely supported preprocessor directive designed to cause the current source file to be included only once in a single compilation.

Thus, #pragma once serves the same purpose as #include guards, but with several advantages, including: less code, avoiding name clashes, and improved compile speed.



它更深入地了解了 article 中的优缺点。 .如果你真的有兴趣,我建议你完整地阅读它,而不仅仅是上面的介绍。

关于include - #pragma once 与 #if !defined MYHEADER_INCLUDED_,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2964100/

相关文章:

node.js - 在Express中渲染jade时包含其他文件的内容吗?

javascript - 以编程方式在高度冲突的环境中包含 JQuery -

c++ - 在 C++ 文件中包含 Objective-C 头文件

visual-studio-2015 - 找不到 corecrt.h : $(UniversalCRT_IncludePath) is wrong

c - C语言预处理分析

c - 函数的宏驱动条件第一个参数

c++ - 如何在 MSVC++ 2005 或 2008 的大型解决方案中找到重复的 header ?

C 预处理器 : Own implementation for __COUNTER__

c++ - 如何生成 setter 和 getter,并使用 C++ 预处理器定义 Q_PROPERTY()

c++ - 不能为 CVOpenGLESTextureGetName 和 CVOpenGLTextureGetName 做 typedef