From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ac6f6c30c45f808a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Nick Roberts Newsgroups: comp.lang.ada Subject: Re: Ada equivalent for C-pointer? Date: Sun, 16 Jan 2005 20:39:35 +0000 Message-ID: References: <41E7F653.2F899F47@alfred-hilscher.de> <7107744.J8aUxUzYtP@linux1.krischik.com> <41EA81CC.8090804@nowhere.fi> Content-Type: text/plain; charset=us-ascii X-Trace: individual.net YWoNDlW7TkEUyZx8ESHJbgqSJ2XkakqLWAr3FDP+eHAoj84l0= X-Orig-Path: not-for-mail User-Agent: Gemini/1.45d (Qt/3.3.2) (Windows-XP) Xref: g2news1.google.com comp.lang.ada:7859 Date: 2005-01-16T20:39:35+00:00 List-Id: Niklas Holsti 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