这个问题在这里已经有了答案:
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/