为什么#include之前需要#?
#
的作用是什么?
What is the function of #
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
#
的作用是什么?
What is the function of #
?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
它表示预处理器指令:
#
可能被任意选择为 C 语法中未使用的字符。我认为@
也会同样有效。如果没有表示它的字符,那么区分用于预处理器的代码可能会遇到麻烦 - 您如何判断
if (FOO)
是否应该进行预处理?It denotes a preprocessor directive:
#
was probably chosen arbitrarily as an otherwise unused character in C syntax.@
would have worked just as well, I presume.If there wasn't a character denoting it, then there would probably be trouble differentiating between code intended for the preprocessor -- how would you tell whether
if (FOO)
was meant to be preprocessed or not?因为
#
是引入预处理器语句的标准前缀。在早期的 C 编译器中,预处理器是一个单独的程序,它将处理所有预处理器语句(类似于早期 C++“编译器”,例如 cfront 生成 C 代码)并为编译器生成 C 代码(它可能仍然是一个单独的程序,但现在它也可能只是编译器的一个阶段)。
#
符号只是一个有用的字符,可以被预处理器识别并执行操作,例如:等等。
Because
#
is the standard prefix for introducing preprocessor statements.In early C compilers, the pre-processor was a separate program which would handle all the preprocessor statements (similar to the way early C++ "compilers" such as cfront generated C code) and generate C code for the compiler (it may still be a separate program but it may also be just a phase of the compiler nowadays).
The
#
symbol is just a useful character that can be recognised by the preprocessor and acted upon, such as:and so on.
这是因为 # 是一个指示符,表明它是一个预处理器语句
,意味着在编译代码之前,它将包含文件 stdio.h
It's because # is an indicator that its a preprocessor statement
meaning before it compiles your code, it is going to include the file stdio.h
#
是一个预处理器指令。预处理器处理源文件包含 (#include
)、宏定义 (#define
) 和条件包含 (#if
) 的指令。当预处理器遇到这种情况时,它将包含标头,展开宏并继续进行编译。它可用于其他目的,例如使用 #error 指令停止编译。这称为条件编译。
#
is a pre-processor directive. The preprocessor handles directives for source file inclusion (#include
), macro definitions (#define
), and conditional inclusion (#if
).When the pre-processor encounters this, it will include the headers, expand the macros and proceeds towards compilation. It can be used for other purposes like halting compilation using the #error directive. This is called conditional compilation.
我们知道,没有预处理器程序就无法运行。预处理器是#或#include或#define或其他。所以#include 之前需要#。
We know, without preprocessor programm do not run. And preprocessor is # or #include or #define or other. So # is required before #include .