home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20165 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  2.2 KB

  1. Xref: sparky comp.lang.c:20165 vmsnet.alpha:148 cern.alpha:33
  2. Newsgroups: comp.lang.c,vmsnet.alpha,cern.alpha
  3. Path: sparky!uunet!mcsun!sunic!kth.se!news.kth.se!LEVITTE
  4. From: LEVITTE@e.kth.se (Richard Levitte)
  5. Subject: Re: function arg.'s in Alpha's DEC C
  6. In-Reply-To: burow@dxcern.cern.ch's message of Sat, 23 Jan 1993 19:41:39 GMT
  7. Message-ID: <LEVITTE.93Jan25113221@elin.e.kth.se>
  8. Sender: usenet@kth.se (Usenet)
  9. Nntp-Posting-Host: elin.e.kth.se
  10. Organization: Department of TeleTransmission Theory
  11. References: <1993Jan23.194139.17196@dxcern.cern.ch>
  12. Date: Mon, 25 Jan 1993 10:32:21 GMT
  13. Lines: 51
  14.  
  15. >>>>> On Sat, 23 Jan 1993 19:41:39 GMT, burow@dxcern.cern.ch (Burkhard Burow) said:
  16.  
  17. There's some trouble with this:
  18.  
  19. BB> Simplified e.g.
  20.  
  21. BB> void q ( int (*c)() );     /* A. prototype of q                              */
  22.  
  23. BB> void __q( void ( *a)() )   /* B. function with a function as argument        */
  24. BB> {
  25. BB> q( a );                    /* C. pass the function parameter on to q.        */
  26. BB> }
  27.  
  28. BB> For which the C compiler complains:
  29.  
  30. BB> q( a );
  31. BB> ^
  32. BB> %CC-E-PASNOTREFCOM, In this statement, the referenced type of the pointer value
  33. BB> "a" is "Function (...) returning void", which is not compatible with "Function (
  34. BB> ...) returning signed int".
  35. BB> at line number 5
  36.  
  37.  
  38. BB has tried this cast:
  39.  
  40. BB> q( *(void **)&a );        
  41.  
  42. I very surprised that cast worked...
  43.  
  44. BB> Other compilers swallow line B. as is.
  45.  
  46. IMHO, those compilers are wrong!
  47.  
  48. A working cast should be:
  49.  
  50.  q( (int (*)())a);
  51.  
  52. The best, though, would be to make the return types compatible. Why on
  53. earth do you want to give q() a function returning nothing when it
  54. expects a function returning int???? What if q() tries to use that
  55. returned (void) integer?
  56.  
  57. IMHO, there's a design problem here... or just a bug.
  58.  
  59. --
  60. !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++!
  61. ! Richard Levitte, VMS GNU Emacs hacker   ! tel: int+46-8-18 30 99            !
  62. ! Sulv"agen 57, II                        ! fax: none for the moment          !
  63. ! S-126 40 H"agersten                     ! Internet: levitte@e.kth.se        !
  64. ! SWEDEN                                  !                                   !
  65. !-----------------------------------------------------------------------------!
  66.