From: "Nick Roberts" <nick.roberts@acm.org>
Subject: Re: Ada access vs C/C++ pointers and references
Date: Thu, 19 Aug 2004 01:21:37 +0100
Date: 2004-08-19T01:21:37+01:00 [thread overview]
Message-ID: <opscydybapp4pfvb@bram-2> (raw)
In-Reply-To: b47de02.0408181427.25d82fe1@posting.google.com
On 18 Aug 2004 15:27:47 -0700, Keith H Duggar <duggar@mit.edu> wrote:
> [re array indexing]
> As you can see, method two saves one instruction by storing
> and manipulating a memory address directly.
In a loop, there is well known optimisation known (for reasons which
mystify me) as 'strength reduction', which allows a loop such as:
for (i=0;i<n;i++) { ... a[i] ... };
to be transformed into the equivalent of:
for (p=&a[0];p<&a[n];p++) { ... *p ... };
before emitting machine code. So an Ada loop such as:
for i in 1..N loop
... A(i) ...
end loop;
can be expected to be compiled into machine code which is as
efficient as the code that could be produced by using direct address
manipulation.
> First, is it correct to say that Ada access types are more
> similar to C++ references (T&) than they are to C/C++
> pointers (T*) ?
No. Ada access types are very similar to C and C++ pointers, and are
typically implemented and used in (almost) exactly the same way.
The rough Ada equivalent of C++ references are 'aliased objects'.
> Second, does Ada provide any facilities for direct and raw
> memory access by memory address and pointer arithmetic?
Yes it does. There are standard packages System.Storage_Elements and
System.Address_To_Access_Conversions, which provide facilities for
converting between access types and addresses, and performing integer
arithmetic on addresses, as well as Interfaces.C and
Interfaces.C.Pointers which enable Ada programs to access C strings,
arrays, and pointers.
> Third, if Ada does not provide arithmetic pointers do you
> know if this has played any part in acceptance of Ada for
> systems programming or efficiency critical applications?
I don't know (sorry).
> Fourth, have you experienced or can you think of any cases
> where pointer arithmetic has helped to solve a problem that
> would have been more difficult with Ada access types alone?
Not that I can recall.
--
Nick Roberts
next prev parent reply other threads:[~2004-08-19 0:21 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-18 22:27 Ada access vs C/C++ pointers and references Keith H Duggar
2004-08-19 0:21 ` Nick Roberts [this message]
2004-08-19 11:42 ` Marin David Condic
2004-08-19 0:29 ` Jim Rogers
2004-08-19 5:19 ` Ludovic Brenta
2004-08-19 6:21 ` Martin Dowie
2004-08-19 11:55 ` Marin David Condic
2004-08-19 18:01 ` Ludovic Brenta
2004-08-19 7:19 ` j
2004-08-19 7:42 ` Martin Dowie
2004-08-19 12:03 ` Marin David Condic
2004-08-19 7:59 ` Ole-Hjalmar Kristensen
2004-08-19 15:33 ` Keith H Duggar
2004-08-19 21:32 ` Ludovic Brenta
2004-08-19 22:18 ` Hyman Rosen
2004-08-20 7:52 ` Ole-Hjalmar Kristensen
2004-08-19 8:11 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox