From 6311006644775899733
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,e94695845965b249
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1992-11-11 07:58:04 PST
Newsgroups: comp.std.c++
Path: sparky!uunet!taumet!steve
From: steve@taumet.com (Steve Clamage)
Subject: Re: Zero-length structures and pointer comparisons
Message-ID: <1992Nov11.193744.5560@taumet.com>
Organization: TauMetric Corporation
References: <1992Oct28.184135.25475@ucc.su.OZ.AU> <1992Oct30.003946.10484@microsoft.com> <1992Nov4.080805.13496@jyu.fi> <1992Nov10.185247.14128@sophists.com>
Date: Wed, 11 Nov 1992 19:37:44 GMT
Lines: 43

lewis@sophists.com (Lewis G. Pringle) writes:

|In article <1992Nov4.080805.13496@jyu.fi> sakkinen@jyu.fi (Markku Sakkinen) writes:
|...
|>I would first like to return to a much more important, related problem,
|>which somebody brought up here rather recently.
|>Namely, there is nothing in the ARM explicitly saying that
|>p == q  might not yield 1 even when p and q are pointing at two different
|>objects.  This hole makes e.g. some standard idioms in Stroustrup's books
|>implementation dependent.

There is language in the C standard (ANSI 3.3.9, Equality Operators)
which requires that pointers which compare equal point to the same
object (plus some weasel wording).  This is missing from 5.10 of the
ARM and (so far) from the C++ Committee Working Paper.  This issue
should probably be addressed.

|Given code like:

|char* start = new char [10];
|char* end   = start+10;
|char* p     = start;

|assert ((p >= start) && (p <= end));	// 1. this is gauranteed by ANSI-C
|p += 10;
|assert ((p >= start) && (p <= end));	// 2. this is gauranteed by ANSI-C
|p = start;
|p--;
|assert (! ((p >= start) && (p <= end))); // 3. ???????

|Is the last assertion portable? ARM/ANSI-C References?

The first two are also guaranteed by 5.9 in the ARM.

The third example does not have defined behavior in Standard C or C++.
You are allowed to create an address one unit past the end of an array,
but you are not necessarily allowed to create an address ahead of the
array.  The expression "p--" is not necessarily valid, and the following
comparison has no defined semantics.  See ANSI C 3.3.8 and ARM 5.9.
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com
Vice Chair, ANSI C++ Committee, X3J16


