🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #2185

Re: Pointers to functions in method definitions

#2185
From: Gordie Freedman
Date: Tue, 05 Jan 1993 08:22
62 lines
1986 bytes
In article <C0CAtI.KqM@knot.ccs.queensu.ca> alastair@hecate.phy.queensu.ca  
(A.B. McLean) writes:
> POINTERS TO FUNCTIONS IN METHOD DEFINITIONS
> 
> I want to write a method that will accept a pointer to a C function.
> For example, let the function be a simple Gaussian:-
> 
> void gaussian(x,a,y)
> float x,a[],*y;
> {
>   float arg;
>   
>   arg = (x-a[2])/a[3];
>   *y += a[1]*exp(-arg*arg);
> }
> 
> In the interface file I would expect (Kernigham amd Ritchie section 5.11)
> the method definition to look like 
> 
> - methodName:void(*gaussian)(float, float*, float*);
> 
> and in the implementation file I may have
> 
> - methodName:void(*gaussian)(float, float*, float*)
> {
>   // ...
>   return self;
> }
> 
> When I try to do this the compiler gives me the message
> 
>   parse error before `void'
>   
> Any suggestions ?
> 
> Alastair McLean
> alastair@hecate.phy.queensu.ca

This should do it:

- methodName:(void (*) (float, float*, float*)) gaussian
{
	return self;
}

Hope this works for you, I just tried this:

- doit : (void (*) (int, int)) foo :(int) x :(int) y
{
	// do something
}

in some obj-c code and it worked.

Remember, the syntax for declaring parameters to obj-c methods is different  
than declaring parameters for C functions, objc uses a "cast"-like syntax for  
parameter declarations in methods.

-- 

--- Gordie Freedman gordie@cyclesoft.com  NeXTMail Yes! ---
>>> Thou shalt not inline functions more complicated than 20 
Technical Details
Message-ID: <1993Jan5.082236.23079@netcom.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!yamanote!gordie
References: <C0CAtI.KqM@knot.ccs.queensu.ca>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!yamanote!gordie
From: gordie@cyclesoft.com (Gordie Freedman)
Subject: Re: Pointers to functions in method definitions
Message-ID: <1993Jan5.082236.23079@netcom.com>
Sender: gordie@netcom.com
Reply-To: gordie@cyclesoft.com
Organization: Dolphin Software
References: <C0CAtI.KqM@knot.ccs.queensu.ca>
Date: Tue, 5 Jan 1993 08:22:36 GMT
Lines: 63