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

  1. Path: sparky!uunet!olivea!decwrl!pa.dec.com!engage.pko.dec.com!nntpd.lkg.dec.com!jit345.bad.jit.dec.com!diamond
  2. From: diamond@jit345.bad.jit.dec.com (Norman Diamond)
  3. Newsgroups: comp.std.c
  4. Subject: Re:  can a pointer cast to a void* be compared to (void*)0 ?
  5. Message-ID: <1993Jan25.015214.22668@nntpd.lkg.dec.com>
  6. Date: 25 Jan 93 01:52:14 GMT
  7. References: <C0nzI2.CqM@cs.psu.edu> <1993Jan16.015545.26580@thunder.mcrcim.mcgill.edu> <alien.02pi@acheron.amigans.gen.nz> <28570@dog.ee.lbl.gov>
  8. Sender: usenet@nntpd.lkg.dec.com (USENET News System)
  9. Reply-To: diamond@jit.dec.com (Norman Diamond)
  10. Organization: Digital Equipment Corporation Japan , Tokyo
  11. Lines: 50
  12.  
  13. In article <28570@dog.ee.lbl.gov> torek@horse.ee.lbl.gov (Chris Torek) writes:
  14. >In article <alien.02pi@acheron.amigans.gen.nz> alien@acheron.amigans.gen.nz
  15. >(Ross Smith) writes:
  16. >>standard does not require pointers to functions to be castable to/from any
  17. >>other pointer type.
  18.  
  19. >Yes (or rather, the effect is undefined or unspecified or otherwise
  20.  
  21. If a converted pointer is used to call a function that has a type that is
  22. not compatible with the type of the called function, the behavior is undefined.
  23. By intuitive implication, I'd say that if the converted pointer is used to call
  24. a function that has a type compatible with the converted pointer, it works.
  25.  
  26. >>(1) Are pointers to different types of function required to be castable to
  27. >>each other?
  28.  
  29. >Yes; however, the result is up to the implementation.  Your only guaranteee
  30. >is that if the result is then cast *back* to the `correct' type [...]
  31. >the final result can be used to *call* that function; I am somewhat
  32. >less certain that it must compare equal to the original pointer.
  33.  
  34. It must compare equal.
  35.  
  36. >>(2) If a compiler does allow casting between "ordinary" pointers and function
  37. >>pointers, does the rule about null pointers remaining null still apply?
  38.  
  39. >Note, however, that the null pointer constant [blah blah blah...]
  40.  
  41. Doesn't look like he asked about that one though.
  42.  
  43. If an implementation says that an object-or-incomplete pointer is allowed to
  44. be cast to a function pointer (or vice-versa), then see what the implementation
  45. says if the original pointer happens to be null.  If the implementation doesn't
  46. say, and you've just been lucky so far in playing with undefined behavior, then
  47. it's up to you to decide if you want to continue depending on luck.
  48.  
  49. >Another question (which belongs in comp.std.c; note followup header):
  50. >do null pointer constants, cast or assigned to pointers to functions
  51. >of different types, then to a common type, compare equal?
  52.  
  53. If two pointers to function types are both null pointers or both point to the 
  54. same function, they compare equal.  But you can't use this to compare two
  55. incompatible function pointer types because of the constraints.  So this
  56. reduces to the question, if a null function pointer is cast to a different
  57. type of function pointer, is the result still a null pointer?  Oh good, yes.
  58. [ANSI classic 3.3.9 and last paragraph of 3.2.2.3.]
  59. --
  60. Norman Diamond                diamond@jit.dec.com
  61. If this were the company's opinion, I wouldn't be allowed to post it.
  62. Pardon me?  Or do I have to commit a crime first?
  63.