home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / cplus / 1754 < prev    next >
Encoding:
Text File  |  1992-12-11  |  1.1 KB  |  28 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!microsoft!hexnut!jimad
  3. From: jimad@microsoft.com (Jim Adcock)
  4. Subject: Re: Zero-length structures and pointer comparisons
  5. Message-ID: <1992Dec11.233039.12249@microsoft.com>
  6. Date: 11 Dec 92 23:30:39 GMT
  7. Organization: Microsoft Corporation
  8. References: <1992Dec8.103218.27689@lth.se> <9234423.15066@mulga.cs.mu.OZ.AU> <KANZE.92Dec10174617@slsvdnt.us-es.sel.de>
  9. Lines: 17
  10.  
  11. In article <KANZE.92Dec10174617@slsvdnt.us-es.sel.de> kanze@us-es.sel.de (James Kanze) writes:
  12. |We already *have* this function.  Try the following:
  13. |
  14. |    void*    ptr1 ;
  15. |    void*    ptr2 ;
  16. |    int    cmp = memcmp( &ptr1 , &ptr2 , sizeof( void* ) ) ;
  17. |
  18. |This works on all implementations I can think of.  Is it guaranteed?
  19. |(Ie: can pointers also hold undefined padding information which may
  20. |vary in a random fashion.  Note that "memcmp" is *not* guaranteed to
  21. |work on struct's.)
  22.  
  23. Not guaranteed, nor does there have to be random padding for it to not
  24. be guaranteed.  All the bits could be used, but there could be multiple
  25. bit combinations mapping to the same underlying memory address.  Early
  26. PCs and OSs being an example.
  27.  
  28.