Sign in Join

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

Mailing lists / fpc-pascal / 2007-12

Local compiler options

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Adriaan van Os

Suppose, I want to use a compiler directive locally and reset it after that.

GPC has {$local ...} and {$endlocal}. FPC in mac-mode has {$push} and {$pop}, e.g.

{$push}
   i:= longword( -1)
{$pop}

I didn't find an equivalent for FPC in delphi or objfpc mode. All I can think of is

{$ifopt R+}
{$define local_RangeCheck}
{$endif}
{$R-}
   i:= longword( -1)
{$ifdef local_RangeCheck}
{R+}
{$endif}

This is a bit ugly and not fully reliable, e.g. try

{$mode objfpc}
program TestLocal;
var i: longint;
begin
{$R+}
{$ifopt R+}
{$define local_RangeCheck}
{$R-}
{$endif}
   i:= longword( -1);
{$ifdef local_RangeCheck}
{$R+}
{$endif}
end.

Any comments ?

Of course, longword( -1) using constants is just one example of the use of local compiler directives. The issue at hand is broader than that.

Regards,

Adriaan van Os

Reply by email

Jonas Maebe
to Adriaan van Os
Adriaan van Os wrote 11 lines
I didn't find an equivalent for FPC in delphi or objfpc mode. All I can think of is {$ifopt R+} {$define local_RangeCheck} {$endif} {$R-} i:= longword( -1) {$ifdef local_RangeCheck} {R+} {$endif}

That's indeed the classic way to do it in TP/FPC/Delphi. I'm not aware of any other way.

Show quoted text 16 lines
This is a bit ugly and not fully reliable, e.g. try {$mode objfpc} program TestLocal; var i: longint; begin {$R+} {$ifopt R+} {$define local_RangeCheck} {$R-} {$endif} i:= longword( -1); {$ifdef local_RangeCheck} {$R+} {$endif} end.

That's a bug in the scanner, please submit a bug report.

Jonas

Reply by email