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

Pierre Free Pascal pierre at freepascal.org
Wed Jul 15 11:47:07 CEST 2015


> > {$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



More information about the fpc-pascal mailing list