From: bourguet@my-deja.com
Subject: Re: Are unconstrained arrays passed by references?
Date: 1999/08/10
Date: 1999-08-10T00:00:00+00:00 [thread overview]
Message-ID: <7opbch$bca$1@nnrp1.deja.com> (raw)
In-Reply-To: wcc907jhl4c.fsf@world.std.com
In article <wcc907jhl4c.fsf@world.std.com>,
Robert A Duff <bobduff@world.std.com> wrote:
> bourguet@my-deja.com writes:
[...]
> > 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.
That's what I though, but I wanted to make sure.
Is there a way to guarantee a pass by reference for a given type?
(I seem to recall that in the spitbol package ACT use pragma
volatile to this effect) And for a subtype? (So one can use this
way to create a subtype of string, making this function savier)
> 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.
That's a good raison to use the type char_array which is provided by
the bindings (perhaps as a subtype of a type in Interfaces.C or
I.C.Strings) to declare constants.
BTW, I'd not have passed a slice, due to the warning of not using
expression.
> Of course C doesn't *have* packing, so ...
I though that one raison for which several types in C may have
different pointer size what to make it possible to use packed arrays
of char. But I may be wrong.
-- Jean-Marc
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
next prev parent reply other threads:[~1999-08-10 0:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-08-10 0:00 Are unconstrained arrays passed by references? bourguet
1999-08-10 0:00 ` Robert A Duff
1999-08-10 0:00 ` bourguet [this message]
1999-08-10 0:00 ` Tucker Taft
1999-08-10 0:00 ` Robert Dewar
1999-08-11 0:00 ` Larry Kilgallen
1999-08-10 0:00 ` Ted Dennison
1999-08-11 0:00 ` Robert A Duff
1999-08-11 0:00 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox