home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.next.programmer
- Path: 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
-
- 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
-
-