What is #if 0
-
I hate
#if 0
:mad:. It's not so bad if the code commented out is small, but when large pieces of code are bracketed with these you can find yourself analyzing code only to find, when you get to the top, that you've been wasting your time and the code isn't even part of the product. This has happened to me many times. If the programmer simply commented it out the syntax highlighting will stop such problems from ever occurring. SteveStephen Hewitt wrote:
I hate #if 0
me too. i use this purpose instead...
#ifdef DEBUG
#define DPRINT printf
#else
void DPRINT(...) {}
#endifthis way, in debug mode, we could
DPRINT()
something, which will not been took in account in release mode (and more, the compiler will optimize a call toDPRINT()
in release). for instance :int Foo() {
DPRINT("Foo()\n");
int i = 654;// modification of i... DPRINT("Foo output : %d\\n", i); return i;
}
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VisualCalc 3.0] -
Stephen Hewitt wrote:
I hate #if 0
me too. i use this purpose instead...
#ifdef DEBUG
#define DPRINT printf
#else
void DPRINT(...) {}
#endifthis way, in debug mode, we could
DPRINT()
something, which will not been took in account in release mode (and more, the compiler will optimize a call toDPRINT()
in release). for instance :int Foo() {
DPRINT("Foo()\n");
int i = 654;// modification of i... DPRINT("Foo output : %d\\n", i); return i;
}
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VisualCalc 3.0]you can #if 0 the code which needs to be ignored in both debug and release build, i.e. older logic to solve a problem, etc.
-Prakash
-
I've seen in many source codes, some statements written in
#if 0
block something like: #if 0 printf("Blah Blah"); #endif Please tell me what is the meaning of#if 0
in the code above.[Message Deleted]
-
I hate
#if 0
:mad:. It's not so bad if the code commented out is small, but when large pieces of code are bracketed with these you can find yourself analyzing code only to find, when you get to the top, that you've been wasting your time and the code isn't even part of the product. This has happened to me many times. If the programmer simply commented it out the syntax highlighting will stop such problems from ever occurring. SteveYes steve u r definetly correct. But this is not supposed to be used to large chunks of code. it is more of an debugging approach than just saving old code. Tip: Always it is a good option to try to put a breakpoint to know if this code is compiled or not. a breakpoint cannot be inserted in any code that is not compiled. Hope this helps. kvprasad your future is what you think
-
[Message Deleted]
-
I hate
#if 0
:mad:. It's not so bad if the code commented out is small, but when large pieces of code are bracketed with these you can find yourself analyzing code only to find, when you get to the top, that you've been wasting your time and the code isn't even part of the product. This has happened to me many times. If the programmer simply commented it out the syntax highlighting will stop such problems from ever occurring. SteveStephen Hewitt wrote:
If the programmer simply commented it out...
But nested comments are not allowed. That's where
#if 0
is of use.
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
-
Stephen Hewitt wrote:
If the programmer simply commented it out...
But nested comments are not allowed. That's where
#if 0
is of use.
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
True. Steve
-
I hate
#if 0
:mad:. It's not so bad if the code commented out is small, but when large pieces of code are bracketed with these you can find yourself analyzing code only to find, when you get to the top, that you've been wasting your time and the code isn't even part of the product. This has happened to me many times. If the programmer simply commented it out the syntax highlighting will stop such problems from ever occurring. SteveI agree that large blocks of
#if 0
'd code are annoying but VS2005 improves things a lot by greying it out. It even greys out (for example)#ifdef _DEBUG
blocks when_DEBUG
is not defined.
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
-
Imtiaz Murtaza wrote:
I've seen in many source codes, some statements written in #if 0 block something like: #if 0 printf("Blah Blah"); #endif Please tell me what is the meaning of #if 0 in the code above
it simply means the code in side the block is ignore for compilation and will not appear in the final build. it is similar to saying
#if !defined(SOME_BUILD_FLAG) or #if FALSE #endif
since the dev wanted the code to be explicitly removed from compilation he used#if 0 #endif
directive
-Prakash
I believe that in Visual C++ 6.0 there is a key combination that will take you to / from #if and #endif but Microsoft in their 'wisdom' removed this very handy functionality from VC++.NET 2001. Yes, thanks Microsoft... Personally, when I need to comment out large chunks of code, I use #if defined dfkagtljarogh #end if // defined dfkagtljarogh where dfkagtljarogh is the result of some random keystrokes. Copy and paste to make sure that two instances match, and then it is not too bad to use Find to jump from beginning to end or vice versa. And as for being unable to nest /* ... */ comments in C++, this is an abomination that should never have been put into the language. Is there any reason whatsoever why C++ (or C even) HAVE TO REFUSE to allow such useful nested comments? Thanks again, Microsoft. Some C++ compilers do allow this. Shraddhan
-
I believe that in Visual C++ 6.0 there is a key combination that will take you to / from #if and #endif but Microsoft in their 'wisdom' removed this very handy functionality from VC++.NET 2001. Yes, thanks Microsoft... Personally, when I need to comment out large chunks of code, I use #if defined dfkagtljarogh #end if // defined dfkagtljarogh where dfkagtljarogh is the result of some random keystrokes. Copy and paste to make sure that two instances match, and then it is not too bad to use Find to jump from beginning to end or vice versa. And as for being unable to nest /* ... */ comments in C++, this is an abomination that should never have been put into the language. Is there any reason whatsoever why C++ (or C even) HAVE TO REFUSE to allow such useful nested comments? Thanks again, Microsoft. Some C++ compilers do allow this. Shraddhan
Shraddhan wrote:
And as for being unable to nest /* ... */ comments in C++, this is an abomination that should never have been put into the language. Is there any reason whatsoever why C++ (or C even) HAVE TO REFUSE to allow such useful nested comments?
yes i agree with you and that is one thing that I hate in VC++ compiler.
-Prakash