views:

24

answers:

1

Hi,

I have got a statement in my code:

#if DEBUG==0

this works fine in gnu g++ but it fails in VC++. Can anyone explain what is wrong with this.

I have already read msdn help on this topic. so, if debug is defined as 1 then this is false i.e.0, so it should work and similarly if debug=0

Can anyone suggest how to correct this. My code has to be compiled both in linux and win.

Thanks

A: 

Leave it like:

#if DEBUG

Though I should add that typically one checks if DEBUG is defined, not if it is 1. To declare you simply say:

#define DEBUG

Check if it is not defined with:

#ifndef DEBUG
Neil
I know, but this is not my code. I am just including someone's header file in my code which has got this statement and I can't just change it.
You could check and redefine, e.g. `#ifdef DEBUG` `#undef DEBUG` `#define DEBUG 1` `#endif`, but that breaks the `#define DEBUG 0` case. It ought to be possible to solve that too? Although I suspect you can just ignore it, or use an `#ifdef NDEBUG` test - e.g. `#ifdef NDEBUG` `#undef DEBUG` `#define DEBUG 0` `#else` then the case above.
Rup
Just do an #ifdef DEBUG followed immediately by #if DEBUG and in the else do #undef DEBUG so that ultimately DEBUG remains consistenly defined if debug is in effect and undefiend otherwise as it would be normally. +1 to Rup for the idea. :)
Neil