Sign in Join

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

Mailing lists / fpc-pascal / 2001-02

Problem using a function as a parameter

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Mario Thaten

Hi everybody,

I've got a maybe simple question. Today I stumbled about a problem I can't determine. The way I saw it in Turbo Pascal years ago, I tried to implement a function as a parameter to another function. I'll send some example code below.

fpc yells at it with an Error: Wrong amount of parameters specified. Is this not implemented in fpc or am I stuck somewhere else?

Thanks for your hints in advance,

yours, Mario

Here's some example code to show my problem:

--8<--

type funcparam = function(x : real):real;
   function f1(x : real):real;
   begin
      f1:=1/(x*x+1);
   end;
   function f2(x : real):real;
   begin
      f2:=x*x+1;
   end;
   function integral(a,e : real; f:funcparam):real;
   begin
      integral:=(f(a)+f(e))*0.5*(e-a);
   end;
begin
   writeln(integral(1,3,f1));
   writeln(integral(1,3,f2));
end.

-->8--

.~. Mario Thaten () /V\ /( )\ "There are just 2 rules in life: ^ ^ Always be yourself, but never mind to change."

Reply by email

Michael Van Canneyt
to Mario Thaten
Mario Thaten wrote 14 lines
Hi everybody, I've got a maybe simple question. Today I stumbled about a problem I can't determine. The way I saw it in Turbo Pascal years ago, I tried to implement a function as a parameter to another function. I'll send some example code below. fpc yells at it with an Error: Wrong amount of parameters specified. Is this not implemented in fpc or am I stuck somewhere else? Thanks for your hints in advance, begin writeln(integral(1,3,f1)); writeln(integral(1,3,f2));
Change this to
   writeln(integral(1,3,@f1));
   writeln(integral(1,3,@f2));

Or use the -So command-line parameter for more TP compatibility. Either should work.
This is probably in the FAQ, and surely in the documentation :-)

Michael.

Reply by email

Mario Thaten
to Michael Van Canneyt
Michael Van Canneyt wrote 7 lines
Change this to writeln(integral(1,3,@f1)); writeln(integral(1,3,@f2)); Or use the -So command-line parameter for more TP compatibility. Either should work. This is probably in the FAQ, and surely in the documentation :-)

I probably must have overread this.

Thanks to Michael!

Yours, Mario

PS: Btw., is there a special reason, why the mailing list server is overwriting the "Reply-To:"-Header? This has become really unpopular on many lists.

.~. Mario Thaten () /V\ /( )\ "There are just 2 rules in life: ^ ^ Always be yourself, but never mind to change."

Reply by email