Jump to content
  • Advertisement
Sign in to follow this  
3DModelerMan

Macro question

This topic is 3391 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

Advertisement
Just to be a bit more explicit, a \ at the end of a line escapes the newline. Multi-line macros are one of the few places this trick comes in handy.

If you are using C++, be aware that there are usually superior options to macros. If you tell us what the macro is supposed to do, we might be able to show you a nicer and safer alternative.

Share this post


Link to post
Share on other sites
It's worth pointing out that \ will also escape the end of C++ comments. I've heard horror stories of bugs caused by accidentally escaping the ends of a comments that took weeks to find.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zipster
It's worth pointing out that \ will also escape the end of C++ comments. I've heard horror stories of bugs caused by accidentally escaping the ends of a comments that took weeks to find.

Now that I was not aware of. Thanks for sharing [smile]

Share this post


Link to post
Share on other sites
Well macros can be usefull for small things that get called over and over, that wouldn't really make since to put in a function and pass all the data you need the same every time. So I thought I would use macros.

Share this post


Link to post
Share on other sites
Quote:
Original post by 3DModelerMan
Well macros can be usefull for small things that get called over and over, that wouldn't really make since to put in a function and pass all the data you need the same every time. So I thought I would use macros.


Usually, inline or template functions get you the same benefits, with type safety and other benefits too.

Again, if you show us the macro, we can tell you how it might be replaced.

Share this post


Link to post
Share on other sites
Quote:
Original post by 3DModelerMan
Well macros can be usefull for small things that get called over and over, that wouldn't really make since to put in a function and pass all the data you need the same every time. So I thought I would use macros.

I will bet you $20 that your compiler (assuming it's gcc or MSVC) can optimize better than you can. Don't make things a macro just because they're small. Macro's are an absolute nightmare to debug and they lack type safety and scope. Any decent compiler will inline such a small function and optimize the @#$% out of your code :)

As Donald Knuth said: "Premature optimization is the root of all evil."

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!