home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19414 < prev    next >
Encoding:
Text File  |  1993-01-08  |  1.5 KB  |  36 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!usc!sdd.hp.com!ux1.cso.uiuc.edu!news.cso.uiuc.edu!lyra.scs.uiuc.edu!mcdonald
  3. From: mcdonald@aries.scs.uiuc.edu (J. D. McDonald)
  4. Subject: Re: Is that ansi ?
  5. References: <1992Dec30.203127.25625@jpradley.jpr.com> <725809262snz@rcsl.demon.co.uk> <1993Jan8.142730.20697@osf.org>
  6. Message-ID: <mcdonald.28@aries.scs.uiuc.edu>
  7. Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
  8. Organization: UIUC SCS
  9. Date: Fri, 8 Jan 1993 15:02:20 GMT
  10. Lines: 24
  11.  
  12. In article <1993Jan8.142730.20697@osf.org> daniel@moonshine.osf.org (Daniel Dardailler) writes:
  13.  
  14. >A compiler is reporting the following warning:
  15.  
  16. >  "void * and function pointers are not convertible to each other"
  17.  
  18. >when encountering:
  19.  
  20. >       void * p = (void *) func ;   /* func of any kind */
  21.  
  22.  
  23. I'm afraid it's true, and one of the most serious faults of ANSI C.
  24.  
  25. Function pointers are orthogonal to everything else.  What you can do
  26. is somehow convert them to an integer type and convert that to 
  27. void * pointer and then go back. The standard itself does not 
  28. guarantee that the conversion will get back the right answer however.
  29. (For those who need a proof, checked with Doug Gwyn, that this can be done:
  30. enclose the function pointer in a struct, write out the struct to a 
  31. file using fwrite, then read back in into a char array of the correct size.
  32. This is guaranteed to work.) Another way is to try and use unions. This
  33. is not absolutely guaranteed to work.
  34.  
  35. Doug McDonald
  36.