Jump to content
  • Advertisement
Sign in to follow this  
Storyyeller

commenting with define

This topic is 3537 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, everyone, I started teaching myself c++ a couple weeks ago. Today I had a question I figured I might as well try posting here. I was under the impression that when you use #define, it blindly replaces all occurrences before compiling beings, so I did
#define FOO //
FOO x++;

It compiled fine, but for some reason, the statements executed, even though they were supposed to be commented out. What did I do wrong? I hope this isn't a stupid question.

Share this post


Link to post
Share on other sites
Advertisement
Comments are stripped before #defines are processed.

I hope you weren't planning to do that for real, though....

Share this post


Link to post
Share on other sites
Quote:
Original post by Codeka

I hope you weren't planning to do that for real, though....


It was the best way I could think of for enabling and disabling many statements easily

Share this post


Link to post
Share on other sites
Quote:
Original post by Storyyeller
Quote:
Original post by Codeka

I hope you weren't planning to do that for real, though....


It was the best way I could think of for enabling and disabling many statements easily


Why not just use // in front or the line? It's less characters than FOO anyway.
Or for a longer statement, just use /* at the start and */ at the end of what you want to comment out.

Share this post


Link to post
Share on other sites
Quote:
Original post by Chadwell
Why not just use // in front or the line? It's less characters than FOO anyway.
Because it wouldn't allow him to conditionally disable a large number of nonconsecutive lines.

BTW, Storyyeller, there's a hackish and ugly way of doing this:

#define FOO if(0)

But yeah, #ifndef is your friend here.

Share this post


Link to post
Share on other sites
Quote:
Original post by Codeka
Comments are stripped before #defines are processed.


Is that specific to certain compilers, or standard?
Perhaps I have misunderstood, but I regularly comment out defines in XCode, using gcc, and they are not compiled.

Share this post


Link to post
Share on other sites
Quote:
Original post by scratt
Quote:
Original post by Codeka
Comments are stripped before #defines are processed.


Is that specific to certain compilers, or standard?
Perhaps I have misunderstood, but I regularly comment out defines in XCode, using gcc, and they are not compiled.


lol, if you comment the defines, then they will get stripped thus will not be compiled.

pass me some of those beers, tnx. ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by owl
Quote:
Original post by scratt
Quote:
Original post by Codeka
Comments are stripped before #defines are processed.


Is that specific to certain compilers, or standard?
Perhaps I have misunderstood, but I regularly comment out defines in XCode, using gcc, and they are not compiled.


lol, if you comment the defines, then they will get stripped thus will not be compiled.

pass me some of those beers, tnx. ;)


lol
I guess i read it the wrong way around.
i.e. Misinterpreting comments are stripped, as meaning // is stripped, before #define is processed, thus exposing #define.
Which it obviously does not.

My bad. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!