/* comment */

Posted By: Siwler

/* comment */ - 01/18/12 22:43

I have seen many comments inside .c/.h codes while for search of my unsolved answers, and I have noticed that so fare all use this character // comments// for engine compiler to ignore it.
I understand if your using it for 2-3 lines of comments, but when it come to comments that take 10-15 lines of codes using this // for every line I find it to be a lot of unnecessary work.

So here is a little trick I came across that I'm sure most of you knew about it just in case someone didn't, it might make their explanatory comments(witch I appreciate so much) easier to work with:

use this before the comment /* then close it again before the last comment */. Don't leave any working code in between these characters /* function main()*/ your engine will ignore it.

small example:

Code:
/* start of my comment
next line of my comment
another line of comment
and yet another line of comment
etc ......
*/ end of my comment

function main() // using it for one line of comments



Do make shore to close it after you open it, otherwise it will ignore entire code in your file.

I don't know maybe it looks cool or something just using these characters // for each line of comments. I'm all about simple and fast, I hope this helped someone out.
Posted By: PadMalcom

Re: /* comment /* - 01/18/12 22:49

You got it wrong, it is supposed to be /* ... */

This is the common C comment, no magic laugh
Posted By: Siwler

Re: /* comment /* - 01/18/12 22:58

yes you are right sorry
Posted By: WretchedSid

Re: /* comment /* - 01/18/12 23:04

The problem is that this type of comment isn't greedy but has lazy behavior, so once you have to comment out such a comment it gets pretty nasty...
Posted By: Shadow969

Re: /* comment /* - 01/19/12 00:34

this way of commenting doesn't support embedding comments into each other, besides most editors allow commenting/uncommenting a block with // instead of manually commenting each line.
Posted By: Damocles_

Re: /* comment /* - 01/19/12 10:33

I also hate the behavior, that the first */ leaves the "comment space"

This way its hard to quickly comment out a large codeblock when
there are "subcomments" with /* */ in it.

The last */ should determine the end of the commentblock.
But on the other hand this is a reliquia from the 70s,
and cant be changed for compatability reasons.
Posted By: WretchedSid

Re: /* comment /* - 01/19/12 10:43

Actually it could be changed as existing code wouldn't break =/
But yeah, /* */ is the old style of commenting (// is C89 or C99?!) and should be used careful.

Oh, and thanks for repeating me guys tongue
Posted By: Sajeth

Re: /* comment /* - 03/19/12 09:26

When commenting out parts of the code for testing, just do it like this:
Code:
/*
void foobar()
{
dosomething();
dosomethingelse();
}
//*/


When you want to include the code again, you just have to add a / at the beginning. Magic!

For comments, I use the // functions of my editor. I think it feels more distinguishable.
Posted By: FBL

Re: /* comment /* - 03/19/12 11:41

use
#ifdef somethingundefined
...
#endif

to comment any comments
Posted By: Damocles

Re: /* comment /* - 03/21/12 04:43

Quote:


/*
void foobar()
{
dosomething();
dosomethingelse();
}
//*/



Thats actually a very nifty trick!
Never though about that one, haha.
Speeds up toggeling commenting of blocks quite a bit.

Will use that in Java.
Posted By: sivan

Re: /* comment /* - 03/21/12 07:50

this #define-ifdef-ifndef-else-endif thing is also really useful when you want to compare the performance of 2 different solutions for the same task (I'm just doing it)!
Posted By: Gordon

Re: /* comment /* - 03/31/12 13:32

The #ifdef also lets you add functionality only when something else is defined like say the blocking define for a module i.e. modname_h. I use this it my latest contribution to handle if the loading bar manager is in the program. It first off controls whether I need to include the semaphore manager and then adds support for calling the loading bar manager... If I don't need the loading bar it configures for running without it.
© 2024 lite-C Forums