[fpc-pascal] Ignoring function results

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Sat May 20 15:35:20 CEST 2017


On 20/05/17 12:30, Bart wrote:
> On 5/20/17, Mark Morgan Lloyd <markMLl.fpc-pascal at telemetry.co.uk> wrote:
>> According to the Programmer's Guide 1.3.41, {$EXTENDEDSYNTAX OFF} has> the effect of permitting the result of a function to be ignored.
> Isn't that just the other way around?
> "Extended syntax allows you to drop the result of a function. Thismeans that you can use a function call as if it were a procedure.By default this feature is on. You can switch it off using the {$X-}or {$EXTENDEDSYNTAX OFF}directive."

Just a mo, let me have another shot at that in case I was doing 
something stupid...

it's definitely got to be on for optional parameters to be accepted, and 
that appears to be the default state if {$mode objfpc}{$H+} is at the 
top of the unit.

The curious thing is that in the cold light of day I can't get 
$EXTENDEDSYNTAX to have any effect on the function result. I'll admit 
what I'm doing:

operator <= (var a: TDateTimeArray; const s: TDateTime): boolean;

begin
   result := Length(a) > 0;
   SetLength(a, Length(a) + 1);
   a[High(a)] := s
end { <= } ;

operator + (const a: TDateTimeArray; const s: TDateTime): TDateTimeArray;

var     b: boolean;

begin
   result := a;
   if Length(result) = 0 then
     { b := } result <= s
   else
     result[High(result)] += s
end { + } ;

If I uncomment the boolean assignment it works. Where I appeared to be 
last night was that setting $EXTENDEDSYNTAX OFF had the above working, 
but I'm now having trouble duplicating it. And I hadn't touched a drop :-)

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list