[fpc-pascal] Hack for C-like macro functions — will it work in future?
Роман
runewalsh at inbox.ru
Wed Sep 24 02:59:39 CEST 2014
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? ._.
More information about the fpc-pascal
mailing list