home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / vms / 21847 < prev    next >
Encoding:
Text File  |  1993-01-24  |  2.0 KB  |  59 lines

  1. Newsgroups: comp.os.vms
  2. Path: sparky!uunet!mcsun!dxcern!burow
  3. From: burow@dxcern.cern.ch (Burkhard Burow)
  4. Subject: functions as arguments in DEC C
  5. Message-ID: <1993Jan23.211019.6955@dxcern.cern.ch>
  6. Organization: CERN European Laboratory for Particle Physics
  7. Date: Sat, 23 Jan 1993 21:10:19 GMT
  8. Lines: 49
  9.  
  10.  
  11. I'm having trouble passing functions as arguments on an Alpha running VMS and
  12. 'DEC C for OpenVMS AXP V1.2-000'
  13.  
  14. My application generates 'wrapper' routines which pass along functions to
  15. other routines. The wrapper routines do not know the type of the functions they
  16. are passing along.
  17.  
  18. Simplified e.g.
  19.  
  20. void q ( int (*c)() );     /* A. prototype of q                              */
  21.  
  22. void __q( void ( *a)() )   /* B. function with a function as argument        */
  23. {
  24. q( a );                    /* C. pass the function parameter on to q.        */
  25. }
  26.  
  27. For which the C compiler complains:
  28.  
  29. q( a );
  30. ^
  31. %CC-E-PASNOTREFCOM, In this statement, the referenced type of the pointer value
  32. "a" is "Function (...) returning void", which is not compatible with "Function (
  33. ...) returning signed int".
  34. at line number 5
  35.  
  36.  
  37. Silicon Graphics 2.0.1 ANSI generates a similar warning, but can be satisfied
  38. by casting 'a' in line B. as follows:
  39.  
  40. q( *(void **)&a );        
  41.  
  42. Other compilers swallow line B. as is.
  43.  
  44. QQQuestion: How do I force DEC C to accept line B.
  45.             i.e. How do I cast the parameter 'a', such that it is acceptable
  46.                  as a an argument for any type of function?
  47.             i.e. For those of you who like IQ,SAT tests and the like:
  48.                          The cast to (void *) of a pointer to an object.
  49.                  is like
  50.                          The cast to _______ of a pointer to a function.
  51.  
  52. thanks,
  53. burkhard      burow@vxdesy.cern.ch
  54.  
  55. P.S My apologies to those of you who may have already caught this article in
  56.     comp.lang.c,cern.alpha,vmsnet.alpha. A colleague spotted it there, and 
  57.     pointed out that c.o.vms might be the best place to look for an answer.
  58.  
  59.