[Harbour] #xtranslate equivilant in C

Przemyslaw Czerpak druzus at acn.waw.pl
Fri Dec 5 05:45:24 EST 2008


On Wed, 03 Dec 2008, Pritpal Bedi wrote:

Hi Pritpal,

> In PRG code I can control the debug info like this:
> #ifndef __DBG_TB__
> #   xtranslate hb_ToOutDebug( [<x,...>] ) =>
> #endif
> Is there any equivalent to this feature in C?

No. In C you can use only #define with quite similar conditions to
Harbour and Clipper (in xHarbour #define is modified and does not
pass it).

> My goal is to replace  
> #ifdef __SOME__ 
> hb_ToOutDebug(...) } 
> #endif 
> with 
> hb_ToOutDebug(...) } 
> and the #define stays at the top of the file.

The C preprocessor works in different way then Harbour/Clipper
one but here it can be resolved in similar way.
In #define you have to specify number of parameters. So Just simply
make a trick to force fixed number of parameters:

#ifdef USE_DEBUG
#  define  MY_OUTDEBUG( d ) hb_ToOutDebug d
#else
#  define  MY_OUTDEBUG( d )
#endif

and then in source code use:
   MY_OUTDEBUG( ( p1, p2, p3, ) )

We are using parenthesis to group list of parameters as one param.

If you look at Harbour source code then you will find that exactly
the same trick is made by HB_TRACE() functions.

best regards,
Przemek


More information about the Harbour mailing list