Sign in Join

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

Mailing lists / fpc-pascal / 2017-05

Ignoring function results

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Mark Morgan Lloyd

According to the Programmer's Guide 1.3.41, {$EXTENDEDSYNTAX OFF} has the effect of permitting the result of a function to be ignored.

However it also appears to (at least) prohibit functions/procedures with optional parameters: can these be controlled separately?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Bart
to Mark Morgan Lloyd
Mark Morgan Lloyd 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. This means 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."

Bart

Reply by email

Mark Morgan Lloyd
to Bart
Bart wrote
On 5/20/17, Mark Morgan Lloyd 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]

Reply by email