View Full Version : #if

09-15-2005, 06:58 PM
So I remember learning about a year ago that you could use #if/#if 0 to basically comment out immense portions of code, no matter what types of comments or nested comments there were in the code. This was really handy in robotics when we made some code that could have been better (we had a "Code Graveyard", complete with an Ascii grave and flowers), but I kind of forgot the syntax for it. Can anyone help? Does anyone know whether it is complier-specific or or whther it will also work in C++?

Thanks in advance. I know the question was a little odd and a bit specific, but hey, if someone tells me the syntax again, it would be extremely handy.

Oh, and I would just ask the people in robotics, but those who were good at programming in the club basically all left to go to universities. Arun's quite good, but I don't think he knows this, because I asked him earlier.

09-15-2005, 07:30 PM
If you want to comment something out in C++, you can use // to comment a single line or /* and */ to comment out a large block of code (or anything else you want). I have never heard of #if/if# 0 before.

09-15-2005, 07:59 PM
You're thinking of /*


But # is allowed in some languages as signifiying a comment.

09-15-2005, 08:15 PM
Um, no, that is not what I am thinking of. I am definitely thinking of #if.


09-15-2005, 08:58 PM
What you are talking about is compiler ifs. Although I personally have never used them yet, the syntax should be like this:

#if <Statement using #defined variables only>



If the statement is true, then the compiler compiles the code within that if... If not, then it is left out of the program.


09-15-2005, 09:35 PM

I think the syntax for the MASSIVE coment-out is like this:

#if 0
//There is stuff in here.

I am almost certain that's how it went. Thank you, soccr. It's actually really handy when you want to just take huge blocks out of your program in no time without deleting the code.