问题
I have a C code:
...
void caller() {
#define YES 1
#define NO 0
}
...
Will the both #define
lines execute when caller
is called/executed, or will they execute at compile-time only.
回答1:
The prerpcessor macros don't execute, they are just named fragments of the code which will be replaced by the preprocessor to theirs content if you use them. Read more about preprocessor macros here.
So, after preprocessing, your code will be:
void caller() {
}
Let assume you use the YES
macro after you #define
it:
#define YES 1
#define NO 0
void caller() {
printf("My answer is: %d", YES);
}
After preprocessing the code above will be the following:
void caller() {
printf("My answer is: %d", 1);
}
来源:https://stackoverflow.com/questions/43862311/when-will-this-execute