🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #52745

Re: function call as pointer

#52745
From: Richard Levitte
Date: Mon, 01 Jun 1992 20:44
37 lines
1951 bytes
>>>>> On 1 Jun 92 12:01:12 GMT, rmq@michlin.mathematik.uni-stuttgart.de (Ralf Quatember) said:

> Given is a function 

> double H(x); ...

> and a second 

> double V(x, *f); ...

> Now my problem: I wanna use a parameter f as a pointer to H(x) (or other
> functions) to use in V(...) like it does qsort(...); 
> How can I manage this?

 double V(x,f)	/* K&R style */
     whatever x;
     double (*f)();
 {
   return (*f)(x); /* ... say, you probably want more code around this */
 }

or ANSI style

 double V(whatever x, double (*f)(whatever))	/* ANSI style */
 {
   return (*f)(x); /* ... say, you probably want more code around this */
 }

'whatever' is whatever type you want to use, of course...

--
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
! Richard Levitte, System manager       ! tel: int+46-8-790 64 23           !
! Royal Institute of Technology         ! fax: int+46-8-791 76 54           !
! Department of Teletransmition Theory  ! Internet: richard@ttt.kth.se      !
! S-100 44 Stockholm, Sweden            !                                   !
!---------------------------------------------------------------------------!
Technical Details
Message-ID: <LEVITTE.92Jun1214409@elixir.lne.kth.se>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic2!kth.se!news.kth.se!levitte
References: <1992Jun1.120112.17630@news.uni-stuttgart.de>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,75125a4d279019d0,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1992-06-01 15:30:10 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sunic2!kth.se!news.kth.se!levitte
From: levitte@lne.kth.se (Richard Levitte)
Subject: Re: function call as pointer
In-Reply-To: rmq@michlin.mathematik.uni-stuttgart.de's message of 1 Jun 92 12:01:12 GMT
Message-ID: <LEVITTE.92Jun1214409@elixir.lne.kth.se>
Sender: usenet@kth.se (Usenet)
Nntp-Posting-Host: elixir.lne.kth.se
Organization: Royal Institute of Technology, Stockholm
References: <1992Jun1.120112.17630@news.uni-stuttgart.de>
Distribution: gnu
Date: Mon, 1 Jun 1992 20:44:09 GMT
Lines: 37