#define blah #ifdef -help! (C not C++)

Programming, for all ages and all languages.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:#define blah #ifdef -help! (C not C++)

Post by Candy »

JoeKayzA wrote:
Solar wrote: This can get really nasty when you're applying this to C++ code, where converting a complex object to string (to satisfy operator<<() ) can get really expensive.
A bit OT, just out of interest: Do you know whether there is a good or common solution against this problem?

cheers Joe
I'm now using the debug {...} I discovered above, which make clear to your compiler that it can leave out all that is in there. If you place your entire debug calls in there it should optimize them out, in any case, it won't call them.

If you want a generic solution, gcc supports an attribute called pure which marks a function as one that you can call less than the indicated amount of times without any side effects. Converting an object to a temporary string representation is one of them (at least, I think). You need to watch out with it however, since it'll cause less exceptions etc. too, in the worst case none where you should've been getting one.
Post Reply