B
Bryan Parkoff
"#define" can only be inside the global scope before main() function.
"#if" can be tested after "#define" is executed. The problem is that
"#define" can't be inside main() function. I do not wish to create multiple
functions which they look almost identical in C++ source code. The C++
compiler should be able to compile one Test() function into two almost
identical functions before they are translated into the machine language
object. The machine language object has two Test() functions, but they
exclude some line parts. First Test() function uses printf("1\n") and
second Test() function uses printf("2\n").
It is the same example that you use MACRO to test the conditional
defines before some lines can be inserted or removed.
If there is no way to test it at compile time, I would have to manual
pasting one Test() function into multiple Test() functions in C++ source
code. Please advise.
Bryan Parkoff
#include <stdio.h>
#define A 1
void Test(void)
{
#if (A == 1)
printf("1\n");
#endif
#if (A == 2)
printf("2\n");
#endif
}
int main(void)
{
Test();
#undef A
#define A 2
Test();
return 0;
}
"#if" can be tested after "#define" is executed. The problem is that
"#define" can't be inside main() function. I do not wish to create multiple
functions which they look almost identical in C++ source code. The C++
compiler should be able to compile one Test() function into two almost
identical functions before they are translated into the machine language
object. The machine language object has two Test() functions, but they
exclude some line parts. First Test() function uses printf("1\n") and
second Test() function uses printf("2\n").
It is the same example that you use MACRO to test the conditional
defines before some lines can be inserted or removed.
If there is no way to test it at compile time, I would have to manual
pasting one Test() function into multiple Test() functions in C++ source
code. Please advise.
Bryan Parkoff
#include <stdio.h>
#define A 1
void Test(void)
{
#if (A == 1)
printf("1\n");
#endif
#if (A == 2)
printf("2\n");
#endif
}
int main(void)
{
Test();
#undef A
#define A 2
Test();
return 0;
}