From 4834079901938573334
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,e94695845965b249
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1992-12-10 10:30:39 PST
Newsgroups: comp.std.c++
Path: sparky!uunet!mcsun!Germany.EU.net!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: fjh@munta.cs.mu.OZ.AU's message of Wed, 9 Dec 1992 12:41:49 GMT
Message-ID: <KANZE.92Dec10174617@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> <9234423.15066@mulga.cs.mu.OZ.AU>
Date: 10 Dec 92 17:46:17
Lines: 32

In article <9234423.15066@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU
(Fergus James HENDERSON) writes:

|> dag@seldon.control.lth.se (Dag Bruck) writes:

|> What I propose is that we define a *standard library function* which computes
|> a total ordering on pointers. This would work on virtually any system
|> without imposing undue constraints on the implementation. Programs written
|> for Intel architectures would not slow down, but the template collection class
|> writers get their total ordering. It should make everyone happy! :-)

|> int compare_pointers(const void *, const void *);
|>     /* Returns negative, zero, or positive in the same manner as strcmp().
|>        Perhaps in the interests of tradition and unreadability it should
|>        be called ptrcmp() instead of compare_pointers() :-) */

We already *have* this function.  Try the following:

	void*	ptr1 ;
	void*	ptr2 ;
	int	cmp = memcmp( &ptr1 , &ptr2 , sizeof( void* ) ) ;

This works on all implementations I can think of.  Is it guaranteed?
(Ie: can pointers also hold undefined padding information which may
vary in a random fashion.  Note that "memcmp" is *not* guaranteed to
work on struct's.)
--
--
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


