Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-07

will be work macro with name of the unit?

8 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ulrich

Hi,

I have this unit, but when I compile it, I get this error:

Illegal unit name XXX_Parser. The unit is saved under dfm_rrparser.pas.

Second question:

Why not displayed $INFO directive in the message window (I have enabled -vi switch in command line)?

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

Thanks

Roman

Michael Van Canneyt
to ulrich
ulrich wrote 5 lines
Hi, I have this unit, but when I compile it, I get this error: Illegal unit name XXX_Parser. The unit is saved under dfm_rrparser.pas.

The unit name must always match the file name.
This is logical, because otherwise the compiler can never find it if a reference to the unit is made in a uses clause.

Show quoted text 5 lines
Second question: Why not displayed $INFO directive in the message window (I have enabled -vi switch in command line)?

It shows it here:
home: >fpc tm.pp -vwi
Target OS: Linux for x86-64
Compiling tm.pp
User defined: compiled with XXX_
tm.pp(10,17) Error: Illegal unit name: XXX_parser
tm.pp(16,16) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted
Error: /usr/local/bin/ppcx64 returned an error exitcode

So probably a lazarus issue ?

Michael.

Sven Barth
to ulrich: I have this unit, but when I compile it, I get this error: Illegal unit name XXX_Parser.…
"ulrich" wrote 10 lines
Hi, I have this unit, but when I compile it, I get this error: Illegal unit name XXX_Parser. The unit is saved under dfm_rrparser.pas. Second question: Why not displayed $INFO directive in the message window (I have enabled

-vi switch in command line)?

Show quoted text 20 lines
{$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.

Regards,
Sven

Pierre Free Pascal
to Sven Barth
Show quoted text 21 lines
> {$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

ulrich
to Pierre Free Pascal

Dne 15.7.2015 v 11:47 Pierre Free Pascal napsal(a):

Show quoted text 44 lines
>> {$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 - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Thanks for your answer

Roman

ulrich
to Michael Van Canneyt: The unit name must always match the file name. This is logical, because otherwise the…

Dne 15.7.2015 v 10:16 Michael Van Canneyt napsal(a):

Show quoted text 14 lines
On Tue, 14 Jul 2015, ulrich wrote: > Hi, > > I have this unit, but when I compile it, I get this error: > > Illegal unit name XXX_Parser. The unit is saved under dfm_rrparser.pas. The unit name must always match the file name. This is logical, because otherwise the compiler can never find it if a reference to the unit is made in a uses clause.

I understand this. I thought that the compiler searches the unit by file name and unit name is stored inside the unit. Test if it is desired unit would be trivial - but I guess you're right - it would be pointless.

Show quoted text 24 lines
> > Second question: > > Why not displayed $INFO directive in the message window (I have > enabled -vi switch in command line)? It shows it here: home: >fpc tm.pp -vwi Target OS: Linux for x86-64 Compiling tm.pp User defined: compiled with XXX_ tm.pp(10,17) Error: Illegal unit name: XXX_parser tm.pp(16,16) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted Error: /usr/local/bin/ppcx64 returned an error exitcode So probably a lazarus issue ? Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Sven Barth
to ulrich
"ulrich" wrote 19 lines
Dne 15.7.2015 v 10:16 Michael Van Canneyt napsal(a): > > > On Tue, 14 Jul 2015, ulrich wrote: > >> Hi, >> >> I have this unit, but when I compile it, I get this error: >> >> Illegal unit name XXX_Parser. The unit is saved under dfm_rrparser.pas. > > > The unit name must always match the file name. This is logical, because > otherwise the compiler can never find it if a reference to the unit is > made in a uses clause. > I understand this. I thought that the compiler searches the unit by file

name and unit name is stored inside the unit. Test if it is desired unit would be trivial - but I guess you're right - it would be pointless.

There is a compiler parameter to disable that restriction (check the help output, I don't remember the parameter right now), but it's definitely less tested...

Regards,
Sven

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 24 lines
Am 17.07.2015 08:12 schrieb "ulrich" : > > Dne 15.7.2015 v 10:16 Michael Van Canneyt napsal(a): > >> >> >> On Tue, 14 Jul 2015, ulrich wrote: >> >>> Hi, >>> >>> I have this unit, but when I compile it, I get this error: >>> >>> Illegal unit name XXX_Parser. The unit is saved under dfm_rrparser.pas. >> >> >> The unit name must always match the file name. This is logical, because >> otherwise the compiler can never find it if a reference to the unit is >> made in a uses clause. >> > I understand this. I thought that the compiler searches the unit by file name and unit name is stored inside the unit. Test if it is desired unit would be trivial - but I guess you're right - it would be pointless. There is a compiler parameter to disable that restriction (check the help output, I don't remember the parameter right now), but it's definitely less tested...

-Un, but it is only meant for the system unit, it should not be used for other files.

Michael.