Commenting C++ code - TIPS

R

rajeshb

To toggle between two implementain with just one key stroke:

by removing or adding a single "/" u can toggle between two C++
implementation.
will be usefull when u want 2 test a sample implementation without
deleting the existing one.

adding a single "/" will comment the second implemenation(step 1).
removing the same will comment the first implementation (step 2).

step 1.
~~~~~~~~~~~~~

//*
// implementation one

int i;
int j;
...

/*/
// implementation two

int i;
int j;
...

//*/


step 2.
~~~~~~~~~~~~~

/*
// implementation one

int i;
int j;
...

/*/
// implementation two

int i;
int j;
...

//*/
 
P

Philipp Bachmann

To toggle between two implementain with just one key stroke:
by removing or adding a single "/" u can toggle between two C++
implementation.
will be usefull when u want 2 test a sample implementation without
deleting the existing one.

adding a single "/" will comment the second implemenation(step 1).
removing the same will comment the first implementation (step 2).

Nice idea, indeed. But I'd prefer "#if 0 ... #else ... #endif" instead,
because I consider your solution too tricky to be readable.

#if 1
// implementation one

int i;
int j;
...

#else
// implementation two

int i;
int j;
...

#endif

....

Cheers,
Philipp.
 
J

John Harrison

Philipp Bachmann > said:
Nice idea, indeed. But I'd prefer "#if 0 ... #else ... #endif" instead,
because I consider your solution too tricky to be readable.

Using an IDE that has syntax colouring you would immediately see which block
was commented out. I've never seen an IDE that can colour #if #else #endif
blocks though.

john
 
M

Mike Wahler

John Harrison said:
Using an IDE that has syntax colouring you would immediately see which block
was commented out. I've never seen an IDE that can colour #if #else #endif
blocks though.

IMO an even 'cleaner' solution is to put alternative implementations
in separate files, and include/exclude the desired/undesired files
in the build.

-Mike
 
B

bartek

(...)
Using an IDE that has syntax colouring you would immediately see which
block was commented out. I've never seen an IDE that can colour #if
#else #endif blocks though.

FYI, gvim does it. Maybe it's not an IDE in full-blown-sense-of-the-word,
though, but a bloody useful code editor nonetheless.

Cheers!
 
J

John Harrison

bartek said:
(...)


FYI, gvim does it. Maybe it's not an IDE in full-blown-sense-of-the-word,
though, but a bloody useful code editor nonetheless.

Does it colour the block depending on whether it will be compiled or not?

#if 0
// one colour
#endif

#if 1
// another colour
#endif

That's what struck me as useful about rajeshb's tip.

john
 
B

bartek

Does it colour the block depending on whether it will be compiled or
not?

#if 0
// one colour
#endif

#if 1
// another colour
#endif

That's what struck me as useful about rajeshb's tip.

Certainly. Gvim's C/C++ syntax colour definition treats #if 0 ... #endif
block just like it was a comment.
 
O

Old Wolf

John Harrison said:
Using an IDE that has syntax colouring you would immediately see which block
was commented out. I've never seen an IDE that can colour #if #else #endif
blocks though.

http://www.vim.org/

(or if an IDE does not a shell and an editor make, then set your IDE's
editor to be vim or gvim).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top