home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / next / programm / 7977 < prev    next >
Encoding:
Text File  |  1993-01-04  |  1.1 KB  |  47 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!wupost!cs.utexas.edu!torn!news.ccs.queensu.ca!news
  3. From: alastair@hecate.phy.queensu.ca (A.B. McLean)
  4. Subject: Pointers to functions in method definitions
  5. Message-ID: <C0CAtI.KqM@knot.ccs.queensu.ca>
  6. Keywords: method
  7. Sender: news@knot.ccs.queensu.ca (Netnews control)
  8. Organization: Queen's University, Kingston
  9. Date: Mon, 4 Jan 1993 17:20:06 GMT
  10. Lines: 35
  11.  
  12. POINTERS TO FUNCTIONS IN METHOD DEFINITIONS
  13.  
  14. I want to write a method that will accept a pointer to a C function.
  15. For example, let the function be a simple Gaussian:-
  16.  
  17. void gaussian(x,a,y)
  18. float x,a[],*y;
  19. {
  20.   float arg;
  21.   
  22.   arg = (x-a[2])/a[3];
  23.   *y += a[1]*exp(-arg*arg);
  24. }
  25.  
  26. In the interface file I would expect (Kernigham amd Ritchie section 5.11)
  27. the method definition to look like 
  28.  
  29. - methodName:void(*gaussian)(float, float*, float*);
  30.  
  31. and in the implementation file I may have
  32.  
  33. - methodName:void(*gaussian)(float, float*, float*)
  34. {
  35.   // ...
  36.   return self;
  37. }
  38.  
  39. When I try to do this the compiler gives me the message
  40.  
  41.   parse error before `void'
  42.   
  43. Any suggestions ?
  44.  
  45. Alastair McLean
  46. alastair@hecate.phy.queensu.ca
  47.