Can you please explain this piece of code? [closed]
#include <stdio.h>
#include CONST15
#define CONST2 CONST2*CONST1
#define CONST3 CONST2+CONST2
int main(int argc,char**argv)
{
printf("%\n",CONST3);
}
First, preprocessing, which is the step that expands #defined'd symbols, happens before actual compilation.
Then, I don't think such a symbol can be recursive, but it can be replaced. So if that is the full program, and assuming <stido.h>
doesn't define a CONST15 or a CONST2, you won't get any reasonable results. My compiler gives an error on the #include line that doesn't specify what to include.
However, you might compile it defining some symbols at compile time, such as:
gcc -DCONST15='"math.h"' -DCONST1=3 -DCONST2=5 foo.c
This would give the #include something (harmless) to work with, and provide a value for CONST1 and CONST2.
Then the first define would set CONST2 to 3*5 (just as that, not 15), and then the second define would set CONST3 to 3*5+3*5.
精彩评论