Macro question

Started by
7 comments, last by 3DModelerMan 14 years, 11 months ago
Is there any way to have a macro span multiple lines?
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.
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.
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]
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
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.
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.
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."
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Huh I guess so. Thanks.

This topic is closed to new replies.

Advertisement