home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / std / cplus / 1973 < prev    next >
Encoding:
Internet Message Format  |  1993-01-05  |  4.6 KB

  1. From: pabloh@hpwala.wal.hp.com (Pablo Halpern )
  2. Date: Mon, 4 Jan 1993 23:13:10 GMT
  3. Subject: Re: Nested functions (was: Re: Zero-length structures and pointer comparisons)
  4. Message-ID: <4048@hpwala.wal.hp.com>
  5. Organization: Hewlett-Packard Company
  6. Path: sparky!uunet!pmafire!news.dell.com!swrinde!sdd.hp.com!hpscit.sc.hp.com!hplextra!hpcss01!hpwala!pabloh
  7. Newsgroups: comp.std.c++
  8. References: <1992Dec12.154918.2220@ucc.su.OZ.AU> <1992Dec14.225659.24225@microsoft.com> <1992Dec16.150144.6004@ucc.su.OZ.AU> <BzDJHu.t2@fru
  9. Sender: netnews@hpwala.wal.hp.com
  10. Lines: 90
  11.  
  12. In article <BzDJHu.t2@frumious.uucp>, pat@frumious.uucp (Patrick Smith) writes:
  13. |> Surely one would want to insist on
  14. |> 
  15. |>    p == q   =>   ptrcmp(p,q) == 0
  16. |> 
  17. |> If this weren't true, one wouldn't be able to use ptrcmp as a basis
  18. |> for organizing an ordered binary tree for searching.  Are there any
  19. |> likely-to-be-common uses of ptrcmp which don't need this assumption?
  20. |> 
  21. |> Unfortunately, meeting this condition might be expensive on
  22. |> segmented architectures (according to the many other postings
  23. |> on this subject).
  24.  
  25. I've had it!  Enough blathering about what might be possible or expensive
  26. on segmented architectures!  A segmented architecture does not present as
  27. many difficulties as some people think.  In a segmented machine, like the
  28. 80x86, pointers can be divided into two catagories:
  29.  
  30.     a) Segment with offset ("far" pointers)
  31.     b) Offset-only ("near" pointers)
  32.  
  33. In what is commonly called the "large memory model," only far pointers
  34. are found.  In the "small memory model," only near pointers are found.
  35. It is valid to use both near and far pointers in the same program.
  36.  
  37. Far pointers present no special difficulties for equality tests unless
  38. operating-system operations map multiple segments to the same memory
  39. location, in which case the program is no longer strictly conforming.
  40. (Normalizing pointers, a practice used in some 8086 C compilers, is not
  41. usually necessary.  A compiler that normalizes must also pay the price with
  42. a more complicated equality check.)
  43.  
  44. Near pointers present a problem at first glance, because the segment
  45. information seems to be missing.  But that ignores a fundamental fact about
  46. near pointers:
  47.  
  48.     A pointer can be represented as an offset without a segment IF AND
  49.     ONLY IF THE SEGMENT IS KNOWN OR IMPLIED BY CONTEXT.
  50.  
  51. This means that the compiler can always know the segment part of a near
  52. pointer.  Consider the following code:
  53.  
  54.     void* memcpy(void* s1, const void* s2, size_t n);
  55.     ...
  56.     int *px, *py;
  57.     int s;
  58.     ...
  59.     memcpy(x, y, s);
  60.  
  61. Assume px and py are near (offset-only) pointers.
  62.  
  63. At the point that memcpy is called, px and py might have the same offset.
  64. In order for memcpy to work (and it MUST work if this is a conforming
  65. implementation), either px and py must point into the same segment, OR the
  66. compiler must be able to determine the correct segment for each.  In the
  67. latter case, the segment information must be supplied to memcpy, e.g. in
  68. the conversion from int* to void*.  The important thing to note is that
  69. memcpy CAN distiguish px from py even if they have the same offset.
  70.  
  71. SOOO...  It is already a requirement that two pointers to different objects
  72. must be distinguishable.  It is therefore easy to meet a requirement that
  73. pointers to *different* objects must compare *unequal*.  More difficult, in
  74. light of normalization and OS hanky-panky, is the current ARM requirement
  75. that pointers to the *same* object must compare *equal*.  However as I
  76. stated earlier, OS hanky-panky is non-conforming and normalization is an
  77. implementation decision that carries the price of slower pointer
  78. comparisons.
  79.  
  80. Absolute orderings are a slightly different matter.  In the case of < and
  81. >, one might expect a significant performance improvement if the pointers
  82. are assumed to point into the same array, since the segment part can be
  83. ignored even for far pointers.  A ptrcmp() function might be worthwhile and
  84. should present no special implementation problems for segmented
  85. architectures.  However, systems (like the lisp machine) where pointers
  86. change behind the program's back DO present a problem since the
  87. bit-pattern-based ordering could change even if the equality/inequality
  88. property does not change.  This would argue against *requiring* a ptrcmp()
  89. function.
  90.  
  91. -- 
  92.  
  93. - Pablo
  94.  
  95. ------------------------------------------------------------------------
  96. Pablo Halpern             (617) 290-3542
  97. HP Waltham                pabloh@hpwarq.wal.hp.com
  98.  
  99. I am self-employed, so my opinions *do* reflect those of my employer.
  100. However, they may not reflect the opinions of my client.
  101. ------------------------------------------------------------------------
  102.