From -1865842924568962932
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,9684813612e15361
X-Google-Attributes: gidf78e5,public
From: David R Tribble <david.tribble@noSPAM.central.beasys.com>
Subject: Re: pointers: sizeof(pointer)
Date: 1998/06/26
Message-ID: <35930246.1692@noSPAM.central.beasys.com>#1/1
X-Deja-AN: 366176807
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
Content-Transfer-Encoding: 7bit
References: <slrn6oqcgp.lfi.sbnaran@bardeen.ceg.uiuc.edu> <6mkkaq$dgu@engnews1.Eng.Sun.COM> <3591A612.15DA@aristeia.com> <6mu1lq$fon@engnews1.Eng.Sun.COM>
X-Original-Date: Thu, 25 Jun 1998 21:07:02 -0500
Mime-Version: 1.0
Reply-To: david.tribble@noSPAM.central.beasys.com
Content-Type: text/plain; charset=us-ascii
Organization: BEA Systems, Inc.
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANZMLt+EDnX0m9pzZAQH5HwF6AiEhadVFO0HETRB1Exd3uVJ4QAU8h+/r lSkG3OaE03Vbc35hSCGnwtk9g6b3Da3Y =//xm
Newsgroups: comp.std.c++


Scott Meyers <smeyers@aristeia.com> writes:
>> In the latest MSJ (July), Matt Pietrek explains why 64-bit Windows NT 
>> will use 64-bit pointers and 32-bit longs.  Believe it or not, it's 
>> not just to make life miserable for Unix developers :-)

Steve Clamage wrote:
> I haven't seen the article, but we at Sun agonized for a long
> time over the sizes of basic types in 64-bit Solaris (Sun's
> version of Unix).
> ...
> We came to the conclusion that it was better to break the
> compatibility of int and long and allow a standard integer
> type (instead of only a language extension) to be the same
> size as pointers. Existing 32-bit programs will usually
> continue to work if they assume int and long value ranges are
> compatible. Programs that assume int and long use the same
> amount of storage will break in 64-bit mode.

Digital did the same thing for their 64-bit Alpha CPU.  They
decided that 'int' would stay as 32 bits, and 'long' would be 64
bits wide.  (Pointers were 64 bits wide.)  They also did a few
things to make the transition of old code easier.

For instance,
    printf("%d %ld %p %d", 123L, 123, &x, &y)
produces the correct results even though the arguments are wrong
because all function arguments are pushed onto the stack as 64-bit
values.  So "%d" and "%ld" really mean the same thing, and int
args are silently promoted to long.

Another thing they did was to write-protect the entire lower 4GB
of virtual memory, so that if you convert an int into a pointer
you'll get an invalid address that would SEGV upon indirection.
When we updated our code to support the Alpha, we only had to fix
about 1% of our code (and that code was fishy to begin with),
leaving us with the impression that they did the Right Thing.

> Evidently Microsoft evaluated their tradeoffs differently.

Leave it to Microsoft to come up with a different, and inherently
worse, solution.  I believe that they think of themselves as being
so big and proud that they entirely ignore the technological
lessons learned by others.  Or maybe they're just bad engineers,
and still think that an 'int' ahould be 16 bits.  This is yet one
more example of the way Microsoft forces you to buy into their
world far more than you want to when you port to them - they
don't want you going back to Unix.

-- David R. Tribble, david.tribble@central.beasys.com --
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



