• Advertisement
Sign in to follow this  

preprocessor statements

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

Im currently implementing a profiler. Would you guys say it is harmfull doing something like this considering the ugliness of #ifdef: void somefunc() { #ifdef PROFILER_ACTIVE my profiler code here #endif ... }

Share this post


Link to post
Share on other sites
Advertisement
What's ugly is putting ifdefs everywhere you have profiler code. It'll ugly your code, so you may want to move the ifdefs somewhere more central. I'm not sure how this is typically done these days, but this would be a great use case for AOP (aspect-oriented programming).

Share this post


Link to post
Share on other sites
ick.
You could clean that up by doing the following


//in your profiler.h
#ifdef USING_MY_PROFILER
#define ProfileSample(f) MyProfilerSample(f)
#else
#define ProfileSample(f)
#endif


//in your other code
#include "profiler.h"

void some_function ()
{
ProfileSameple(__FUNCTION__);
...
...
}



that would keep #ifdef's from being everywhere

Share this post


Link to post
Share on other sites
Quote:
Original post by KulSeran
ick.
You could clean that up by doing the following

*** Source Snippet Removed ***

that would keep #ifdef's from being everywhere

ick.
A preprocessor definition that isn't ALL_CAPS_WITH_UNDERSCORES? Evil. Apart from that your solution is good though. I use PP_PROFILE as my #define symbol, so my code looks like:
void function_i_want_to_profile()
{
PP_PROFILE;
// code
}

// profiling source code
#define PP_PROFILE Profile local_profile_object(__FUNCTION__)

Σnigma

Share this post


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

  • Advertisement