comp.lang.ada
 help / color / mirror / Atom feed
From: Dave Thompson <david.thompson1@worldnet.att.net>
Subject: Re: Ada Pointer Size Problem
Date: Mon, 01 Nov 2004 08:14:03 GMT
Date: 2004-11-01T08:14:03+00:00	[thread overview]
Message-ID: <rva1o0tb2kuf5uo1s2bjm32dlmfs2vcdvc@4ax.com> (raw)
In-Reply-To: gHEdd.2724$%h1.850@newsread3.news.pas.earthlink.net

On Thu, 21 Oct 2004 01:56:28 GMT, Jeffrey Carter <spam@spam.com>
wrote:

> Dave Thompson wrote:
> 
> > On Mon, 11 Oct 2004 05:18:58 GMT, Jeffrey Carter <spam@spam.com> 
> > wrote:
> >> 
> >> In C/++, a pointer is an int is an address. In Ada, they're 3
> >> different things.
> > 
> > But (unlike its predecessor B) a C pointer/address is not just an
> > int.
> 
> I meant that a pointer is an int because you can always convert/assign a
> pointer to an int.

Well, in many languages (not just C) you can just assign an integer
(or fixed-point) value to floating-point and vice versa, but I sure
wouldn't say that either "is" the other.

And you can't assign C pointer to integer without conversion; it
violates a constraint. (Or pass as parameter or return as value, since
in C those are always semantically equivalent to assignment.)

You can write the conversion to any integer type explicitly with a
cast, but the result is implementation-defined and may or may not be
useful. For most mainstream systems there is a simple and useful
mapping and that is what any sensible implementation provides, but the
Standard doesn't require it. 

As others have already said, the specific type 'int', which is only
one of the integer types provided by a conforming C, need not be large
enough to handle (all) addresses. In addition to the 286 example, I
have long personal experience of the "classic" (that is, pre-RISC,
still used in emulation) Tandem^WCompaq^WHP NonStop, with three
execution models: IP16, I16P32, and IP32; corresponding basically to
different stages in their CPU/ISA evolution. In the "large" I16P32
model obviously pointer in int doesn't work.

The new-in-C99 names intptr_t and uintptr_t are integer types
guaranteed large enough to losslessly store (with the explicit
conversion) any (data) pointer, but are optional; an implementation
need not provide them if it doesn't have a suitable integer type. As
with all the new <stdint.h> types, there is an associated preprocessor
macro you can test to determine if the type is present, and thus write
code that works-around the omission or at least fails gracefully --
but only with the ugliness typical of preprocessor solutions, as often
discussed here. But machines that actually can't do address arithmetic
-- and thus reasonably support such an integer type -- are for obvious
reasons pretty damn rare if they exist at all, and also (would be)
very unlikely to be able to support the rest of C anyway.

- David.Thompson1 at worldnet.att.net



  parent reply	other threads:[~2004-11-01  8:14 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-10 19:50 Ada Pointer Size Problem skidmarks
2004-10-11  1:38 ` Stephen Leake
2004-10-12 18:44   ` skidmarks
2004-10-13  1:23     ` Jeffrey Carter
2004-10-13  8:07     ` Martin Krischik
2004-10-13 16:27     ` Jean-Pierre Rosen
2004-10-11  5:18 ` Jeffrey Carter
2004-10-21  1:16   ` Dave Thompson
2004-10-21  1:56     ` Jeffrey Carter
2004-10-21  9:54       ` Martin Krischik
2004-10-22  1:09         ` Jeffrey Carter
2004-10-22  7:48           ` Martin Krischik
2004-10-22  9:41             ` Adrien Plisson
2004-10-22 16:50               ` Warren W. Gay VE3WWG
2004-10-24 16:05               ` Martin Krischik
2004-10-23  1:35             ` Jeffrey Carter
2004-10-24 15:52               ` Martin Krischik
2004-10-22  5:41       ` Simon Wright
2004-10-22 18:05       ` Mark Lorenzen
2004-11-01  8:14       ` Dave Thompson [this message]
2004-10-11  8:45 ` Martin Krischik
     [not found]   ` <1c2f5137.0410130505.57e03c@posting.google.com>
2004-10-13 13:37     ` Dmitry A. Kazakov
2004-10-14  3:46     ` Steve
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox