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

  1. Xref: sparky comp.os.vms:21859 comp.lang.c:20137 vmsnet.alpha:144 cern.alpha:31
  2. Newsgroups: comp.os.vms,comp.lang.c,vmsnet.alpha,cern.alpha
  3. Path: sparky!uunet!gatech!usenet.ins.cwru.edu!agate!overload.lbl.gov!dxcern!burow
  4. From: burow@dxcern.cern.ch (Burkhard Burow)
  5. Subject: Re: functions as arguments in DEC C
  6. Message-ID: <1993Jan24.094945.7767@dxcern.cern.ch>
  7. Organization: CERN European Laboratory for Particle Physics
  8. Date: Sun, 24 Jan 1993 09:49:45 GMT
  9. Lines: 84
  10.  
  11.  
  12. In article <1jshf6INNgce@gap.caltech.edu>, carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick) writes:
  13. >In article <1993Jan23.211019.6955@dxcern.cern.ch>, burow@dxcern.cern.ch (Burkhard Burow) writes:
  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. >Well, if you want to cast a as a signed int (which is what the error message
  43. >told you, and your declaration implies, the function q requires as an argument),
  44. >you don't use "*(void **) &a", you use "*(int **) &a".  Have you tried that?
  45.  
  46. Yes, that of course does work. It doesn't help me though.
  47. I guess I wasn't clear enough in my original posting.
  48.  
  49. My intermediate 'wrapper' functions know nothing about the functions they
  50. receive as arguments and pass on to other functions.
  51. That's why I need a cast for saying: 
  52.  'This is a pointer to a function.
  53.   I don't give a flying f*** about the type of argument the function returns.'
  54.  
  55. Just like one can use (void *) to say:
  56.  'This is a pointer to an object.
  57.   I don't give a flying f*** about the type of object.'
  58.  
  59. For the curious, the application is my cfortran.h header file which helps
  60. make mixing C and Fortran as painless as possible.
  61. [cfortran.h is available via anon. ftp at zebra.desy.de.]
  62.  
  63. e.g. To create a Fortran callable qsort(3C) called FQSORT, 
  64.      compile the following 3 line program.
  65.  
  66. #include <stdlib.h>      /* qsort() prototype */
  67. #include "cfortran.h"
  68. FCALLSCSUB4(qsort,FQSORT,fqsort,PVOID,INT,INT,ROUTINE)
  69.  
  70. cfortran.h provides the macro definitions which convert FCALLSCSUB4()
  71. into the (OS/compiler dependant) Fortran callable routine FQSORT.
  72.  
  73. In FCALLSCSUB4() one simply says that the 4th argument is a routine.
  74. i.e. There's no need to specify what type is returned by the routine.
  75.  
  76.          EXCEPT SO FAR FOR DEC C, WHICH I CAN'T CONVINCE, 
  77.          BUT I'M HOPING SOMEONE OUT THERE CAN TELL ME HOW.
  78.  
  79. Of course, one could leave out '#include <stdlib.h>' in order to get
  80. the above to compile under DEC C, but that's hardly in the ANSI C spirit.
  81.  
  82.  
  83. The above trouble, and an even sillier problem with IBM's RS/6000 C compiler,
  84. have got me 1/2 worried that newer versions of other compilers might also
  85. include bogus errors and warnings.
  86. With all this progress, I'll be left longing for the good ol' days, 
  87. when C let you do what you wanted to, without jumping through hoops.
  88.  
  89. A plea to compiler writers:
  90.   Don't force programmers to obey your interpretation of ANSI C.
  91.   Please provide #pragmas so that I can turn off/on an individual check
  92.   around code which is OK.
  93.  
  94. thanks,
  95.