Preprocessor Question: #if A && B 
Author Message
 Preprocessor Question: #if A && B

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.

--



Mon, 01 Apr 2002 03:00:00 GMT  
 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.
--



Mon, 01 Apr 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Preprocessor Question: #if A && B

2. Preprocessor Question: #if A && B

3. Preprocessor Question: #if A && B

4. ***&&&>>> HELP --- CXL --- HELP <<<&&&****

5. Question on && ==

6. Question about &&.

7. Odd trivia question involving && and ,

8. && operator question

9. A question about '&&'

10. Linker error 2001 @&(#&@#&$@

11. Linker error 2001 @&(#&@#&$@

12. Preprocessor confusion - K&R2 4.11.3

 

 
Powered by phpBB® Forum Software