[fpc-pascal] will be work macro with name of the unit?

ulrich romrum at cbox.cz
Thu Jul 16 10:36:26 CEST 2015


Dne 15.7.2015 v 11:47 Pierre Free Pascal napsal(a):
>>> {$IFDEF FPC}
>>>    {$MACRO ON}
>>>    {$IFNDEF XXX_}
>>>      {$DEFINE XXX_:=DFM_RR} // replace prefix
>>>    {$ENDIF}
>>> {$ENDIF}
>>>
>>> {$INFO compiled with XXX_}
>>>
>>> unit XXX_parser;
>>>
>>> {$mode objfpc}{$H+}
>>>
>>> interface
>>>
>>> implementation
>>>
>>> end.
>> Macros are only expanded on whole tokens (aka words). So XXX_ is
>> expanded, but XXX_parser is not. It's the same with C preprocessors by
>> the way.
>
>    This is one of the limitation that we have against
> C preprocessor macros:
>    in C, you would be able to use
> $define XXX_parser XXX_ ## parser
> so that
>    unit XXX_parser;
> would work as you want,
> but I don't think that we ever implemented an equivalent
> inside the Free Pascal compiler.
>    The other aspect is that, according to Michael's answer,
> the information message sent to output is not passed trough
> the preprocessor, because it still prints XXX_, and not DFM_RR.
> I would qualify this as a feature, not a bug, but others
> might disagree on that.
>    This is because the source is parsed by using readcomment method,
> which will never try to replace macros.
>
> Pierre Muller
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
Thanks for your answer

Roman




More information about the fpc-pascal mailing list