comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: Modest proposal, 3 of 3
Date: 1996/11/26
Date: 1996-11-26T00:00:00+00:00	[thread overview]
Message-ID: <dewar.849012584@merv> (raw)
In-Reply-To: 57csa5$7c8@wdl1.wdl.lmco.com


>Van Snyder wrote:
>> BACKGROUND
>> This is OK, because there are only two things you can
>> do with pointers (in a sane language): dereference them and copy them.


I assume that this is a dig at the "pointer arithmetic" in C. If so, it is
misguided.

First, the rather surprising fact. Ada 95 has pointer arithmetic, C does not!

Well that sounds outrageous, what do I mean by it?

In C, a pointer is semantically a rather complex object, it is conceptually
a pointer to an object in the usual manner, together with an offset into
this object. So-called pointer arithmetic merely modifies the offset, and
there is a restriction that the offset may not be adjusted to values outside
the allocated object (with one small glitch that it is allowed to point just
past the end of an array, generating a special pointer that cannot be
dereferenced).

Sure, a typical (but not required) implementation of C is to represent this
semanti object with a single hardware pointer, and not to check for violation
of the restrictions on the offset. This means that typical C *implementations*
but not the C language itself, support completely general pointer arithmetic.

But Ada 95 on the other hand supports quite general pointer arithmetic (see
the type Integer_Address and its operations in System.Storage_Elements).
Of course these are not everyday operations in Ada 95, and would be used
only for certain purposes, e.g. computation of hash codes invlving
pointers, or implementation of a garbage collector. But such tasks can
be done in Ada 95 without going outside the semantics of the language.

I was discussing the standard template library implementation with one of
its authors a few months ago, and one of his complaints about C, and one
of the things he liked about Ada 95, was the availability of general
pointer arithmetic in Ada 95 that allowed certain algorithms involving
hashing of pointers to be written completely portably in Ada 95 that
could not be written in valid portable C.





  reply	other threads:[~1996-11-26  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-22  0:00 Modest proposal, 3 of 3 Van Snyder
1996-11-25  0:00 ` Robert A Duff
1996-11-25  0:00 ` Ken Garlington
1996-11-25  0:00   ` Mark A Biggar
1996-11-26  0:00     ` Robert Dewar [this message]
1996-11-26  0:00 ` Joel VanLaven
replies disabled

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