From 5657900609473809398
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,e94695845965b249
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1992-12-10 08:57:06 PST
Newsgroups: comp.std.c++
Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!jvnc.net!gmd.de!ira.uka.de!slsvaat!josef!kanze
From: kanze@us-es.sel.de (James Kanze)
Subject: Re: Zero-length structures and pointer comparisons
In-Reply-To: dag@seldon.control.lth.se's message of 8 Dec 92 10:32:18 GMT
Message-ID: <KANZE.92Dec10165804@slsvdnt.us-es.sel.de>
Sender: news@us-es.sel.de
Organization: SEL
References: <1992Dec2.111003.23102@jyu.fi> <1992Dec2.205330.10372@meaddata.com>
	<1992Dec4.070720.13056@lth.se> <1992Dec07.222242.18703@microsoft.com>
	<1992Dec8.103218.27689@lth.se>
Date: 10 Dec 92 16:58:04
Lines: 48

In article <1992Dec8.103218.27689@lth.se> dag@seldon.control.lth.se
(Dag Bruck) writes:

|> In <comp.std.c++> jimad@microsoft.com (Jim Adcock) writes:
|> >
|> >If you want to compare addresses, the following works on all computers
|> >and compilers I've ever had to deal with:
|> >
|> >if (((long)ptr_a) > ((long)ptr_b))
|> >	blah();

This won't work with the Intel 80386 C compiler, and I suppose it
won't work when they finally get a C++ compiler.

If you declare the pointers far with the Zortech C++, and compile in
extended mode, it also won't work.

In general, an 80386 pointer can be 48 bits, whereas all of the
compilers I know for the 80386 use 32 bit longs.

|> I would be perfectly happy with a simple work-around, like the one
|> above.  If the standard guarantees that given two pointers of the same
|> type "p" and "q",

|> 	p != q  <=>  long(p) > long(q)  |  long(p) < long(q)

|> I assume this is not the case now, but if a trivial change in the
|> standard document would give us this guarantee, the problem is solved
|> and we need not discuss it anymore.

This is not the case now, see above.

|> If there are any problems, for example, if all significant bits of the
|> pointers will not fit into a long integer, I think we're back to
|> square one again and have to define "operator<" for pointers.  The
|> alternative is of course to dismiss the idea as not worth the trouble.

I favor the latter case.  I don't see any need for long's on a 80386
being bigger than 32 bits.  (If I need more, I'll use an extended
precision Integer package anyway, since my programs generally have to
work on several different machines, most of which *will* still have 32
bit longs.)
--
--
James Kanze                             email: kanze@us-es.sel.de
GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                   -- Beratung in industrieller Datenverarbeitung


