comp.lang.ada
 help / color / mirror / Atom feed
From: Nick Roberts <nick.roberts@acm.org>
Subject: Re: Ada equivalent for C-pointer?
Date: Sun, 16 Jan 2005 20:39:35 +0000
Date: 2005-01-16T20:39:35+00:00	[thread overview]
Message-ID: <gemini.iafg1y001xzht03tw.nick.roberts@acm.org> (raw)
In-Reply-To: 41EA81CC.8090804@nowhere.fi

Niklas Holsti <nobody@nowhere.fi> wrote:

> But according to LRM B.3(68), for an "in out" parameter of an *elementary*
> type (as here) the pointer that is passed to the C function is a pointer
> to a *temporary copy* of the parameter (here Number), not a pointer to the
> parameter itself. This may not be what the C function expects. For
> example, it would not make sense for "wibble" to save the pointer for
> later use.
> 
> (Perhaps this detail is explained in the Wiki page that was referenced.
> For some reason, I couldn't reach that page to read it.)

I think the idea is as follows. Supposing a call is made to Wibble with an 
actual parameter corresponding to Number called Actual. The call first makes
a copy of the value of Actual, then it passes a pointer to that copy as the
parameter Number, and makes the call. Upon return, the value in that
temporary copy is then copied back into Actual. (Hence, it 'works' :-)

The idea is that Actual may, in fact, be a register, or something other than
a straightforward memory location. The temporary copy will be in a
straightforward memory location (suitable to be pointed at by a C pointer).
However, I suspect a possible optimisation, if it so happens that Actual is
in fact stored in a straightforward memory location, is to simply pass a
pointer to Actual; theoretically, the semantics should be the same (in the
absence of aliasing effects).

However, this is all based upon an Implementation Advice clause.
Implementations are necessarily permitted to do something else.

-- 
Nick Roberts



  parent reply	other threads:[~2005-01-16 20:39 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-14 16:41 Ada equivalent for C-pointer? Alfred Hilscher
2005-01-14 17:00 ` Duncan Sands
2005-01-14 20:05   ` tmoran
2005-01-15  5:00     ` Brian May
2005-01-14 22:33 ` Keith Thompson
2005-01-14 23:03   ` Stephen Leake
2005-01-15 15:51     ` Nick Roberts
2005-01-15 18:54       ` tmoran
2005-01-16  1:43         ` Keith Thompson
2005-01-17 21:35       ` Randy Brukardt
2005-01-15  9:09 ` Martin Krischik
2005-01-15 16:03 ` Nick Roberts
2005-01-15 16:27   ` Pascal Obry
2005-01-15 16:50     ` Nick Roberts
2005-01-15 17:11       ` Simon Wright
2005-01-15 18:46         ` Nick Roberts
2005-01-15 17:49       ` Pascal Obry
2005-01-16  8:44       ` Martin Krischik
2005-01-16  9:58         ` Pascal Obry
2005-01-16 11:07           ` Martin Krischik
2005-01-16  8:36     ` Martin Krischik
2005-01-16 15:01       ` Niklas Holsti
2005-01-16 16:02         ` Martin Krischik
2005-01-17 15:33           ` Niklas Holsti
2005-01-16 20:39         ` Nick Roberts [this message]
2005-01-17 21:38     ` Randy Brukardt
2005-01-17 21:45       ` Pascal Obry
2005-01-17 13:11 ` Alfred Hilscher
2005-01-18  7:31   ` Keith Thompson
replies disabled

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