预处理器指令 #if 和普通 if 之间的区别
C 中的预处理器指令 #if
和普通 if
有什么区别?我是C新手。
What is difference between preprocessor directive #if
and normal if
in C? I'm new to C.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
前面带有 # 的语句称为预处理器指令。它们在代码实际编译之前由解析器处理。从使用 Google 的第一次搜索命中开始 (http://www.cplusplus.com/doc/tutorial /预处理器/):
因此#if 将在编译时决定,“正常”if 将在运行时决定。换句话说,
将编译为
如果而不是你编写的
程序实际上会编译为
Statements with # in front of them are called preprocessor directives. They are processed by a parser before the code is actually compiled. From the first search hit using Google (http://www.cplusplus.com/doc/tutorial/preprocessor/):
So a #if will be decided at compile time, a "normal" if will be decided at run time. In other words,
Will compile as
If instead you wrote
The program would actually compile as
预处理器
if
允许您在将代码发送到编译器之前对其进行调节。通常用于阻止标头代码被添加两次。编辑,你的意思是C++,因为它被标记为这样?
http://www.learncpp.com /cpp-tutorial/110-a-first-look-at-the-preprocessor/
Preprocessor
if
allows you to condition the code before it's sent to the compiler. Often used to stop header code from being added twice.edit, did you mean C++, because it was tagged as such?
http://www.learncpp.com/cpp-tutorial/110-a-first-look-at-the-preprocessor/
预处理器 if 由预处理器处理,作为正在编译的程序的第一步。正常的 if 是在程序执行时在运行时处理的。预处理器指令用于启用条件编译,根据不同定义的预处理器常量/表达式使用不同的代码部分。正常的 if 用于控制正在执行的程序中的流程。
The preprocessor if is handled by the preprocessor as the first step in the program being compiled. The normal if is handled at runtime when the program is executed. The preprocessor directive is used to enable conditional compilation, using different sections of the code depending on different defined preprocessor constants/expressions. The normal if is used to control flow in the executing program.