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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a369e9bb4bee1413 X-Google-Attributes: gid103376,public From: Robert A Duff Subject: Re: Are unconstrained arrays passed by references? Date: 1999/08/10 Message-ID: #1/1 X-Deja-AN: 511026596 Sender: bobduff@world.std.com (Robert A Duff) References: <7oomct$t93$1@nnrp1.deja.com> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 1999-08-10T00:00:00+00:00 List-Id: bourguet@my-deja.com writes: > In the Intermetric X bindings, there is something like this in > X.Strings (this is from memory, I may mess up the details but > the principle should be clear): > > subtype char is Interfaces.C.char; > type charp is access all char; > > function Addr (S : String) return charp; > > function To_X (A : System.Address) return charp is > new Unchecked_Conversion... > > function Addr (S : String) return charp is > begin > return To_X (S (S'First)'Address); > end Addr; > > There is a warning to use Addr only with variables and constants > because if the argument was an expression the result may be > dangling before it was of any use. > > I understand how this work if the string is passed by reference, > and why passing unconstrained array by reference make sense, > but as I've not found in the RM indications that it is mandatory > I was wondering if I've missed something or if this code rely on > a probable implementation. This code is relying on a probable implementation. Note: on a machine that doesn't have 8-bit storage units (let's say it's 32-bit-word-addressable), and String is packed, then a slice of a string will normally be passed by copy, if it doesn't happen to be on a word boundary. The copy will normally be done at the call site, and the address of the copy passed. Of course C doesn't *have* packing, so ... - Bob -- Change robert to bob to get my real email address. Sorry.