三个#include卫兵,永远不会破坏? [英] Three #include guards, which will never break?
问题描述
有时程序员会在命令行定义宏,如:
$ gcc -DF1_H ...
$ gcc -DF1_H = 0 ...
$ gcc -DF1_H = 1 ...
标记为#1,#2,#3的以下三行中的一行可提供#include
保护和避免错误可能由冗余#include引入。
每个人都有任何缺陷吗?哪一个永远不会破坏?
#if F1_H / *#1 * /
/ * #if!defined(F1_H)* / / *#2 * /
/ * #ifndef F1_H * / / *#3 * /
#define F1_H
/ *更多东西在这里... * /
#endif
-
lovecreatesbeauty
gcc -DF1_H ...
gcc -DF1_H = 0 ...
gcc -DF1_H = 1 ...
标记为#1,#2,#3的以下三行之一可提供#include
保护和避免错误可能由冗余#include引入。
每个人都有任何缺陷吗?哪一个永远不会破坏?
#if F1_H / *#1 * /
/ * #if!defined(F1_H)* / / *#2 * /
/ * #ifndef F1_H * / / *#3 * /
#define F1_H
/ *更多东西在这里... * /
#endif
-
lovecreatesbeauty
Sometimes programmers will define macros at command line like:
$ gcc -DF1_H ...
$ gcc -DF1_H=0 ...
$ gcc -DF1_H=1 ...
One of following three lines labeled as #1, #2, #3 may provide #include
guard and avoid errors may be introduced by redundant #include. Is
there any flaw with each of them? Which one will never break?
#if F1_H /*#1*/
/*#if !defined(F1_H)*/ /*#2*/
/*#ifndef F1_H */ /*#3*/
#define F1_H
/*more stuff here ...*/
#endif
--
lovecreatesbeauty
gcc -DF1_H ...
gcc -DF1_H=0 ...
gcc -DF1_H=1 ...
One of following three lines labeled as #1, #2, #3 may provide #include
guard and avoid errors may be introduced by redundant #include. Is
there any flaw with each of them? Which one will never break?
#if F1_H /*#1*/
/*#if !defined(F1_H)*/ /*#2*/
/*#ifndef F1_H */ /*#3*/
#define F1_H
/*more stuff here ...*/
#endif
--
lovecreatesbeauty
这篇关于三个#include卫兵,永远不会破坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!