问题描述
是什么在 C #如果和正常如果
之间的区别STRONG>?我是新来的 C
What is difference between preprocessor directive #if
and normal if
in C? I'm new to C.
推荐答案
在他们面前用#语句称为preprocessor指令。它们由分析器处理之前的code为实际上编译。从使用谷歌的第一个搜索命中(http://www.cplusplus.com/doc/tutorial/$p$pprocessor/):
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/):
preprocessor指令是包含在我们的程序,不是程序语句,但为preprocessor指令的code线。这些线总是以哈希符号(#)pceded $ P $。在preprocessor是code的实际编译之前执行的开始,所以preprocessor消化所有这些指令是由语句生成任何code之前。
因此在#if将在编译时决定,正常,如果将在运行时决定。换句话说,
So a #if will be decided at compile time, a "normal" if will be decided at run time. In other words,
#define TEST 1
#if TEST
printf("%d", TEST);
#endif
将编译为
printf("%d", 1);
如果不是你写
#define TEST 1
if(TEST)
printf("%d", TEST);
该计划将实际编译为
The program would actually compile as
if(1)
printf("%d", 1);
这篇关于preprocessor指令#if和正常的,如果区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!