As we all know, C preprocessor allows function-like macros, including ones with empty expansion. They can be very convenient for things that you'll want to disable depending on conditional defines, such as logging or assertions.

#ifdef DEBUG
    #define dprf(...) print_debug_message(__VA_ARGS__)
#else
    #define dprf(...)
#endif

I have a temptation to use this in FPC too. Here's a trick:

{$macro on}
{$ifdef DEBUG}
    {$define Log := ActualLog}
{$else}
    {$define Log := ;//}
{$endif}

if A then
Log('will work until followed by ELSE at all or any statements on the same line (because of ; and //, respectively).');
if B then
  Log('And should not be carried over to the next line, of course!');

Because constant {$ifdef DEBUG} ActualLog(...); {$endif} are rather cumbersome.

This is by design? Can I rely on this behavior in the future? ._.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to