Sign in Join

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

Mailing lists / fpc-devel / 2016-01

macro through command line

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Dmitry Boyarintsev

Hello,

Is it possible to pass a macro through command line (fpc 2.6.4)?
here's an example.
The following code compiles and works as expected:
{$macro on}
{$define A:=5}
begin
  writeln(A);
end.
But, the program
begin
  writeln(A);
end.
fails to compile with the following command line:
fpc -Sm -dA:=5 -va test.pas
The error is
test.pas(2,12) Error: Identifier not found "A"

even though, it seems like -d parameter was handled as it should: [0.009] Handling option "-Sm"
[0.009] interpreting option "-Sm"
[0.009] Handling option "-dA:=5"
[0.009] interpreting option "-dA:=5"
[0.009] Macro A set to 5

Naturally the actual value (5) is respected by conditional $if statements.

Is not possible to declare a global (or unit-specific) macro from command-line?
and they have to be declared in the unit interface part?

The ultimate goal is to actually get a *full path* of a unit during compilation, and I was researching macros as an option to get the information.

thanks,
Dmitry

Reply by email

Jonas Maebe
to Dmitry Boyarintsev
Dmitry Boyarintsev wrote 8 lines
even though, it seems like -d parameter was handled as it should: [0.009] Handling option "-Sm" [0.009] interpreting option "-Sm" [0.009] Handling option "-dA:=5" [0.009] interpreting option "-dA:=5" [0.009] Macro A set to 5 Naturally the actual value (5) is respected by conditional $if statements.

-d sets a compile-time variable, which is not the same as a macro: http://www.freepascal.org/docs-html/prog/progse6.html

Is not possible to declare a global (or unit-specific) macro from command-line?

No.

and they have to be declared in the unit interface part?

Yes, or in an include file included in the unit interface.

Jonas

Reply by email