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

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Zero-length structures and pointer comparisons
  5. Message-ID: <1992Dec18.195647.20074@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1992Dec14.225659.24225@microsoft.com> <1992Dec16.150144.6004@ucc.su.OZ.AU> <BzDJHu.t2@frumious.uucp>
  10. Date: Fri, 18 Dec 1992 19:56:47 GMT
  11. Lines: 89
  12.  
  13. In article <BzDJHu.t2@frumious.uucp> uunet.ca!frumious!pat writes:
  14. >maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  15. >|    I'm not yet convinced it need bear ANY relation to
  16. >|    ==, !=, < etc on pointers.
  17. >
  18. >["it" == ptrcmp]
  19. >
  20. >
  21. >Surely one would want to insist on
  22. >
  23. >   p == q   =>   ptrcmp(p,q) == 0
  24. >
  25. >If this weren't true, one wouldn't be able to use ptrcmp as a basis
  26. >for organizing an ordered binary tree for searching.  Are there any
  27. >likely-to-be-common uses of ptrcmp which don't need this assumption?
  28.  
  29.     Of course: sorts will work perfectly well, as will any
  30. algorithm that doesnt require uniqueness. 
  31.  
  32.     That means this 'unconstrained' version of ptrcmp,
  33. which might well always return 0 as Jim Adcock suggested,
  34. can always be implemented on any machine. Returning 0 always
  35. is a perfectly well defined total order, even if it
  36. makes all pointers look the same.
  37. >
  38. >Unfortunately, meeting this condition might be expensive on
  39. >segmented architectures (according to the many other postings
  40. >on this subject).
  41. >
  42.  
  43.     Thats not the issue. It might be UNIMPLEMENTABLE on
  44. some architectures. In fact, == is UNIMPLEMENTABLE in general
  45. on the 386 in protected mode, given the sloppy definition
  46. of 'same object' in the ARM. Its quite possible on the 386
  47. to have two logical addresses which convert to the 
  48. same linear address, but NOT BE ABLE TO TELL THAT THIS IS THE CASE.
  49. Because to tell implies access to the LDT/GDT and the typical
  50. process is not able to read those tables. A special
  51. operating system function would be required to do this,
  52. and that would make C++ unimplementable on systems not
  53. having this function.
  54.  
  55.     Now assuming we clean up the ARM definition, we have to 
  56. look at
  57.  
  58.     a == b <==> ptrcmp(a,b)==0
  59.  
  60. first, before worrying about preserving partial orders that <
  61. may or may not be. I think the above can be done
  62. when a==b is made sensible, but I'm not sure.
  63.  
  64.     The condition
  65.  
  66.     a<b <==> ptrcmp(a,b)<0
  67.  
  68. cannot posibly be acceptable, since no language
  69. in the ARM requires < to be a partial order, or anything else.
  70. (Except if a,b point into the same array).
  71.  
  72. >
  73. >The converse,
  74. >
  75. >   ptrcmp(p,q) == 0   =>   p == q
  76. >
  77. >seems not quite as essential, but still very useful.  Can anyone
  78. >describe an otherwise reasonable implementation of ptrcmp which
  79. >would _not_ meet this condition?  If not, what's the harm in
  80. >asking for it?
  81. >
  82.  
  83.     If ptrcmp just compared bits, this might be possible.
  84. But then Jims stipulation that ptrcmp might always return
  85. 0 could not hold, and without this possibility a total
  86. order might not be obtainable.
  87.  
  88.     (Recall this was suggested because some underlying
  89. compaction mechanism might move stuff in memory around,
  90. and adjust the pointers. The we might have
  91.  
  92.     a<b at time t0
  93.     a>b at time t1
  94.  
  95. if we just did bit comparisons)
  96.  
  97. -- 
  98. ;----------------------------------------------------------------------
  99.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  100.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  101. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  102.