liwei said:
how can i let the follow marco works in VC6.0
#define TRACE_BEGIN(function) #ifdef DEBUG \
printf("----------------Enterinto%s-----------------\n",function);\
time_t beginTime,endTime;\
time(&beginTime); \
#endif
You can't use '#' expressions inside of a #define.
"It just doesn't work"(tm)
If you have a decent optimizer, you can use this version
and let the optimizer strip out the code when not needed.
#define TRACE_BEGIN(function) time_t beginTime,endTime;\
if (DEBUG) \
{printf("----------------Enterinto%s-----------------\n",function);\
time(&beginTime);}
It has the added benefit of checking your code for
syntax problems no matter how you compile it.
Or, you can swap the # directives around
#ifdef DEBUG
#define TRACE_BEGIN(function) \
printf("----------------Enterinto%s-----------------\n",function);\
time_t beginTime,endTime;\
time(&beginTime);
#else
#define TRACE_BEGIN(function)
#endif
If you are using am 'assert' package, you might want
to use NDEBUG instead of DEBUG, just to be consistant.
If you want to profile your code, doesn't VC have a code
profiling option? Most functions take so little time that
you will find that your profiling code is taking most of the
cpu-time, especially since printf is a slow bastard,
which skews your results. This is magnified if your
'TRACED' function calls other 'TRACED' functions.
You end up profiling your calls to printf, and optimizing
the wrong functions.