From -3321877019797232715
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,e94695845965b249
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1992-12-02 08:47:13 PST
Newsgroups: comp.std.c++
Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
Subject: Re: Zero-length structures and pointer comparisons
Message-ID: <1992Dec2.144857.5061@ucc.su.OZ.AU>
Sender: news@ucc.su.OZ.AU
Nntp-Posting-Host: extro.ucc.su.oz.au
Organization: MAXTAL P/L C/- University Computing Centre, Sydney
References: <1992Nov27.091056.3895@jyu.fi> <1992Nov30.195202.14370@ucc.su.OZ.AU> <1992Dec1.072440.824@jyu.fi>
Date: Wed, 2 Dec 1992 14:48:57 GMT
Lines: 47

In article <1992Dec1.072440.824@jyu.fi> sakkinen@jyu.fi (Markku Sakkinen) writes:
>In article <1992Nov30.195202.14370@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
>>	On the 80x86 machines, with segmented architectures,
>>one might define == and != to comparte BOTH the offset and segment
>>(as required by the ARM and the extra rule you suggested ought to
>>have been in the ARM).
>>
>>	However, the < operator might be implemented to compare
>>ONLY the offset part. This is legal because it is 'implementation
>>defined'. One could create TWO arrays in different segments,
>>and use < to compare relative positions of pointers into
>>these different arrays.
>>
>>This is not a very practical example, Jim can provide a better one
>>perhaps. 
>
>Is this what you mean?
>	if (p == q) ... // the same object (assuming the mentioned correction
>			// to the rules)
>	else if (p < q) ... // in the same segment
>	else if (p > q) ... // in the same segment
>	else ... // the objects must be in different segments!
>If some compilers really work like this (i.e. neither p==q, p<q, nor p>q holds when
>p and q point to different segments, it is indeed possible to write code that would
>behave differently if total order for pointers were required.

	Here's areally contorted example.

	// p & q point to the last byte in an array, the arrays
	// are whole segments

	if(p==q) { // same array }
	else if(p<q) { // p is shorter than q !! }
	else if(p>q) { // p is longer than q !! }
	else { p is the same length as q } // neither p==q, p<q or p>q

The code is stupid and implementation dependent, but it is legal.
If the standard required a total order, the compiler vendor would
have to change the implementation of pointer comparisons to take
the segment into account, as it is the code relies on the implementation
only using the offset part.

-- 
;----------------------------------------------------------------------
        JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
	Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------


