home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19438 < prev    next >
Encoding:
Internet Message Format  |  1993-01-08  |  2.3 KB

  1. Path: sparky!uunet!crdgw1!rdsunx.crd.ge.com!bart!volpe
  2. From: volpe@bart.NoSubdomain.NoDomain (Christopher R Volpe)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Is that ansi ?
  5. Message-ID: <1993Jan8.191358.25333@crd.ge.com>
  6. Date: 8 Jan 93 19:13:58 GMT
  7. References: <1992Dec30.203127.25625@jpradley.jpr.com> <725809262snz@rcsl.demon.co.uk> <1993Jan8.142730.20697@osf.org> <mcdonald.28@aries.scs.uiuc.edu>
  8. Sender: volpe@bart (Christopher R Volpe)
  9. Reply-To: volpe@ausable.crd.ge.com
  10. Organization: GE Corporate Research & Development
  11. Lines: 54
  12. Nntp-Posting-Host: bart.crd.ge.com
  13.  
  14. In article <mcdonald.28@aries.scs.uiuc.edu>, mcdonald@aries.scs.uiuc.edu (J. D. McDonald) writes:
  15. |> In article <1993Jan8.142730.20697@osf.org> daniel@moonshine.osf.org (Daniel Dardailler) writes:
  16. |> 
  17. |> >A compiler is reporting the following warning:
  18. |> 
  19. |> >  "void * and function pointers are not convertible to each other"
  20. |> 
  21. |> >when encountering:
  22. |> 
  23. |> >       void * p = (void *) func ;   /* func of any kind */
  24. |> 
  25. |> 
  26. |> I'm afraid it's true, and one of the most serious faults of ANSI C.
  27.                                                                ^^^^^^
  28.  
  29. You mean "faults of C". This is not new to ANSI C.
  30.  
  31. |> 
  32. |> Function pointers are orthogonal to everything else.  What you can do
  33. |> is somehow convert them to an integer type and convert that to 
  34. |> void * pointer and then go back. The standard itself does not 
  35. |> guarantee that the conversion will get back the right answer however.
  36.  
  37. Huh? Function pointers can no more be converted to integers than they can
  38. be converted into object pointers. There is nothing that says a 
  39. function pointer will even *fit* in an integer or an object pointer.
  40.  
  41. |> (For those who need a proof, checked with Doug Gwyn, that this can be done:
  42. |> enclose the function pointer in a struct, write out the struct to a 
  43. |> file using fwrite, then read back in into a char array of the correct size.
  44. |> This is guaranteed to work.) 
  45.  
  46. And how is this useful?
  47.  
  48. |> Another way is to try and use unions. This
  49. |> is not absolutely guaranteed to work.
  50.  
  51. What are you suggesting he do with the union?
  52.  
  53. |> 
  54. |> Doug McDonald
  55.  
  56. Daniel-
  57.   Just change the declaration to the following:
  58.  
  59.   void (*p)() = (void (*)()) func; /* func of any kind */
  60.  
  61. -Chris
  62.  
  63. -- 
  64. ==================
  65. Chris Volpe
  66. G.E. Corporate R&D
  67. volpecr@crd.ge.com
  68.