Sign in to follow this  

Macro question

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

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

This topic is 3144 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this