
Preprocessor Question: #if A && B
On Thu, 14 Oct 1999 17:27:06 GMT, in comp.lang.c.moderated "Victor Lu"
Quote:
>Given the following preprocessor directives:
>#define A 1
>#define B 0
>#if A && B
>/* Some code here */
>#endif
>Is this legal preprocessor syntax? Will the code after the #if compile?
>Microsoft Visual C++ compiles it if A is 1 and B is 0.
>However, Visual C++ doesn NOT compile it if A is 0 and B is 1.
>Can anyone explain why? Any help is greatly appreciated.
I Think your problem is elsewhere. The syntax is valid and should
prevent the compilation of any code between the #if and the #endif.
Even Visual C gets this right. I'm using VC/C++ 5.0.
--- begin included file---
D:\DAVE>type pp.c
#include <stdio.h>
#define A 1
#define B 0
int main()
{
puts("Are we going to get a surprise?");
#if A && B
puts("Surprise!");
#endif
return 0;
Quote:
}
D:\DAVE>cl pp.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 11.00.7022 for
80x86
Copyright (C) Microsoft Corp 1984-1997. All rights reserved.
pp.c
Microsoft (R) 32-Bit Incremental Linker Version 5.00.7022
Copyright (C) Microsoft Corp 1992-1997. All rights reserved.
/out:pp.exe
pp.obj
D:\DAVE>pp
Are we going to get a surprise?
D:\DAVE>
---end included file---
The results are identical when A is 0 and B is 1 (or when they're both
zero). When both A and B are defined as 1, "Surprise!" is printed.
But it's not really a surprise if they're both 1...
Regards,
-=Dave
Just my (10-010) cents
I can barely speak for myself, so I certainly can't speak for B-Tree.
Change is inevitable. Progress is not.
--