包括用C语法逆天 [英] Include Guards syntax in C
问题描述
您好每一个我想问一个关于包括用C programming.I警卫问题知道有目的的,但在某些codeS我所看到的1的#define之后写的
Hello every one I want to ask a question about include guards in C programming.I know there purpose but in some codes I have seen "1" written after #define like
#ifndef MYFILE_H
#define MYFILE_H 1
什么是这个1的目的是什么?有必要吗 ?
谢谢
What is the purpose of this "1" ? Is it necessary ? Thanks
推荐答案
如果在 MYFILE_H
宏不是在你的code在其他地方使用,这是没有必要的。
It is not necessary if the MYFILE_H
macro is not used elsewhere in your code.
如果它与其他地方使用的 #IFDEF
或的#ifndef
指令喜欢这里:
If it is used elsewhere with an #ifdef
or #ifndef
directive like here:
#ifdef MYFILE_H
那么 1
宏定义,不需要 -
then the 1
is not required in the macro definition-
但如果它像一个在这里#如果
指令其他地方使用的:
but it if it used elsewhere with an #if
directive like here:
#if MYFILE_H
那么 1
(或任何值!= 0
)是必需的宏定义。
then the 1
(or any value != 0
) is required in the macro definition.
请注意这些指令可以在源文件被用来验证头是否被包含。
Note these directives could be used in a source file to verify if the header is included or not.
这篇关于包括用C语法逆天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!