How to comment out chunks of code with comments most conveniently? 
Author Message
 How to comment out chunks of code with comments most conveniently?

Quote:

>During program development, it is very helpful to add statements incrementally
>and at the same time choose between alternate pieces of code. Hence, deletion
>is not desirable, but commenting out is more desirable. In shell scripts this
>is done very convenientally by puting # at the beginning of each line using
>emacs macros. In C however, it is not possible to comment out portions
>because the comments nested in the code may interfere. You also do not want
>to change the comments in the chunk of the code. Is there any convenient
>solution?

As mention in other current threads, you can just put a "#ifdef 0" before
the portion you want to rem out and a "#endif" at the end of that
portion.

You must only be careful of not interfering with other "#ifdef" and
"endif" statements that might overlap on the portion of code you want to
exclude.

Quote:

>Please also contact via email.
>Thanks a lot!

>lbliao

--
Francois Labreque | "The surest sign of the existence of extraterrestrial


I may work for them, but i'm not paid enough to speak for them!


Fri, 12 Mar 1999 03:00:00 GMT  
 How to comment out chunks of code with comments most conveniently?

Quote:

>In C however, it is not possible to comment out portions
>because the comments nested in the code may interfere. You also do not want
>to change the comments in the chunk of the code. Is there any convenient
>solution?

#if 0
blah blah blah
#endif

#if ... #endifs can be nested.

--
James Robinson            "Because we are returning a copy for postfix ++


                                           _The_Complete_C++_Primer_, 2nd ed.



Sat, 13 Mar 1999 03:00:00 GMT  
 How to comment out chunks of code with comments most conveniently?

#define CODETOUSE 0

#if CODETOUSE
call_this_func()
#else
call_that_func()
#endif

Then again, when developing large systems, you might not want to compile too
many times (since it may take several minutes to compile).  So what I do
is to have a temporary (for debug purposes only) global (no flames please,
this gets deleted) similar to the #define thing above.  Then I can just
stop in the de{*filter*} and chose which piece of code I want to use by
setting this global to something.  Or use some sort of run mode :)

Good luck,

Roberto

: Reposting article removed by rogue canceller.

: During program development, it is very helpful to add statements incrementally
: and at the same time choose between alternate pieces of code. Hence, deletion
: is not desirable, but commenting out is more desirable. In shell scripts this
: is done very convenientally by puting # at the beginning of each line using
: emacs macros. In C however, it is not possible to comment out portions
: because the comments nested in the code may interfere. You also do not want
: to change the comments in the chunk of the code. Is there any convenient
: solution?

: Please also contact via email.
: Thanks a lot!

: lbliao

--




----------------------------------------------------------------------



Sat, 13 Mar 1999 03:00:00 GMT  
 How to comment out chunks of code with comments most conveniently?


Quote:
> #define CODETOUSE 0

> #if CODETOUSE
> call_this_func()
> #else
> call_that_func()
> #endif

> Then again, when developing large systems, you might not want to compile too
> many times (since it may take several minutes to compile).  So what I do
> is to have a temporary (for debug purposes only) global (no flames please,
> this gets deleted) similar to the #define thing above.  Then I can just
> stop in the de{*filter*} and chose which piece of code I want to use by
> setting this global to something.  Or use some sort of run mode :)

You say that with such shame!  Absolutely nothing wrong with that
technique.  If anybody flames you for that, they are a moron. :-)

In fact, I often put in tons of printf's during development that I
can switch on and off to get a debug trace, such as

    if (debug) printf("WorkSub: i = %d\n", i);

or some such.




Sun, 14 Mar 1999 03:00:00 GMT  
 How to comment out chunks of code with comments most conveniently?




[snip]

Quote:

> You say that with such shame!  Absolutely nothing wrong with that
> technique.  If anybody flames you for that, they are a moron. :-)

> In fact, I often put in tons of printf's during development that I
> can switch on and off to get a debug trace, such as

>     if (debug) printf("WorkSub: i = %d\n", i);

> or some such.

        Whatever works for the programmer is a good thing.

        I prefer to use something along the lines of...

        #define DEBUG_MODE 1
        #ifdef DEBUG_MODE
        #define DEBUG(x)   (x)
        #else
        #define DEBUG(x)
        #endif

        DEBUG(printf("WorkSub: i = %d\n", i));

        If I want to turn off debugging, I comment out the #define DEBUG_MODE
statement...  Place this in some global header and your set.

--
/////////////////////////////////////////////
// Damond Walker



Mon, 15 Mar 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How to comment out chunks of code with comments most conveniently?

2. Need comments on commenting program

3. Change C++ comments to C-comments

4. Multi-Line Comments Nested in Single Line Comments

5. changing C++ comments // to C comments /*

6. comments on comments

7. changing C++ comments // to C comments /*

8. Converting C++ comments to C comments

9. How VS.NET generates code comment reports

10. code comments in VS.net 2003

11. javadoc style commenting for C code

12. comment my code

 

 
Powered by phpBB® Forum Software