home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / std / cplus / 1541 < prev    next >
Encoding:
Text File  |  1992-11-11  |  2.1 KB  |  54 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Zero-length structures and pointer comparisons
  5. Message-ID: <1992Nov11.193744.5560@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1992Oct28.184135.25475@ucc.su.OZ.AU> <1992Oct30.003946.10484@microsoft.com> <1992Nov4.080805.13496@jyu.fi> <1992Nov10.185247.14128@sophists.com>
  8. Date: Wed, 11 Nov 1992 19:37:44 GMT
  9. Lines: 43
  10.  
  11. lewis@sophists.com (Lewis G. Pringle) writes:
  12.  
  13. |In article <1992Nov4.080805.13496@jyu.fi> sakkinen@jyu.fi (Markku Sakkinen) writes:
  14. |...
  15. |>I would first like to return to a much more important, related problem,
  16. |>which somebody brought up here rather recently.
  17. |>Namely, there is nothing in the ARM explicitly saying that
  18. |>p == q  might not yield 1 even when p and q are pointing at two different
  19. |>objects.  This hole makes e.g. some standard idioms in Stroustrup's books
  20. |>implementation dependent.
  21.  
  22. There is language in the C standard (ANSI 3.3.9, Equality Operators)
  23. which requires that pointers which compare equal point to the same
  24. object (plus some weasel wording).  This is missing from 5.10 of the
  25. ARM and (so far) from the C++ Committee Working Paper.  This issue
  26. should probably be addressed.
  27.  
  28. |Given code like:
  29.  
  30. |char* start = new char [10];
  31. |char* end   = start+10;
  32. |char* p     = start;
  33.  
  34. |assert ((p >= start) && (p <= end));    // 1. this is gauranteed by ANSI-C
  35. |p += 10;
  36. |assert ((p >= start) && (p <= end));    // 2. this is gauranteed by ANSI-C
  37. |p = start;
  38. |p--;
  39. |assert (! ((p >= start) && (p <= end))); // 3. ???????
  40.  
  41. |Is the last assertion portable? ARM/ANSI-C References?
  42.  
  43. The first two are also guaranteed by 5.9 in the ARM.
  44.  
  45. The third example does not have defined behavior in Standard C or C++.
  46. You are allowed to create an address one unit past the end of an array,
  47. but you are not necessarily allowed to create an address ahead of the
  48. array.  The expression "p--" is not necessarily valid, and the following
  49. comparison has no defined semantics.  See ANSI C 3.3.8 and ARM 5.9.
  50. -- 
  51.  
  52. Steve Clamage, TauMetric Corp, steve@taumet.com
  53. Vice Chair, ANSI C++ Committee, X3J16
  54.