#pragma once 和#ifndef的区别

来源:互联网 发布:淘宝韩版男装店 编辑:程序博客网 时间:2024/05/20 11:32
 If your compiler supports "#pragma once",
It will ignore the rest of the header file when it finishes reading this line.
But if you use "#ifndef xxx", "#define xxx", "...", "#endif",
the compiler will go on parsing this file because it thinks that
  there may be some more lines of code after "#endif",
it dare not to drop the rest of the file.

As you see,
if the compiler supports "#pragma once",
using "#pragma once" will accelerate the compiling process.
So people usually write header file like this:

#ifndef XXX
#define XXX

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER

...
...

#endif // XXX