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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!spool.mu.edu!uwm.edu!linac!unixhub!ditka!eagercon!eagercon!eager
  3. From: eager@eagercon.com (Michael J. Eager)
  4. Subject: Re: can a pointer cast to a void* be compared to (void*)0 ?
  5. Message-ID: <1993Jan11.061416.2250@eagercon.com>
  6. Sender: root@eagercon.com (Operator)
  7. Reply-To: eager@eagercon.com
  8. Organization: Eager Consulting
  9. References: <C0nzI2.CqM@cs.psu.edu>
  10. Date: Mon, 11 Jan 1993 06:14:16 GMT
  11. Lines: 24
  12.  
  13. In article CqM@cs.psu.edu, andrew@astro.psu.edu (Andrew Wilcox) writes:
  14. >This may be a FAQ, but I didn't see it in Steve Summit's excellent
  15. >list, so:
  16. >
  17. >Can a pointer which has been cast to a void* be directly compared with
  18. >a (void*)0 in ANSI C, or does the void* have to be cast back to the
  19. >original type before the comparision?  I.e.,
  20. >
  21. >     char* c = 0;
  22. >     void* p = (void*) c;
  23. >     if (p == 0)
  24. >       printf( "yes\n" );
  25. >
  26. >Is this program guaranteed to print "yes"?
  27.  
  28. Yes.  Zero is a "special" pointer value which is guaranteed to be different
  29. from any valid pointer value.  A zero typed pointer value will be
  30. converted (trivially) to a zero void pointer value.
  31.  
  32. ---
  33. Michael J. Eager        Michael.Eager@eagercon.com
  34. Eager Consulting        (415) 325-8077 
  35. 1960 Park Boulevard, Palo Alto, CA 94306-1141
  36.  
  37.