[fpc-pascal] User-defined operators and dummy parameters

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Sat Aug 10 12:04:26 CEST 2013

Is it possible to pass a dummy parameter to a user-defined operator, 
with no expectation that it be referenced?

The following test program compiles OK but fails at runtime with an 
error 217 on all platforms if the record is empty. It works if it 
contains a variant, but not reliably with other types.

program test;

{$mode objfpc}{$H+}

type    t1= array of integer;
         r_= record
//              x: variant

var     a1: t1;
         reduce: r_ = ();

procedure print(const a: t1);

var     i: integer;

   for i := Low(a) to High(a) do
     Write(a[i], ' ');
end { print } ;

operator + (const r: r_; const a: t1) s: variant;

var     i: integer;

   s := 0;
   for i := Low(a) to High(a) do
     s += a[i]
end { + } ;

//  a1 := t1([1,2,3,4,5]);      Doesn't work without tuple support
   SetLength(a1, 5);
   a1[0] := 1;
   a1[1] := 2;
   a1[2] := 3;
   a1[3] := 4;
   a1[4] := 5;
   WriteLn('+/ a1:');
   WriteLn(reduce + a1);

This is of no particular importance, I'm just exploring capabilities.

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