From: dan.r.mcleran@seagate.com (Dan McLeran)
Subject: Re: Pass by reference
Date: 9 Apr 2004 05:44:39 -0700
Date: 2004-04-09T05:44:39-07:00 [thread overview]
Message-ID: <19b0e504.0404090444.376ab672@posting.google.com> (raw)
In-Reply-To: mailman.226.1081468908.327.comp.lang.ada@ada-france.org
>
> > I am investigating using Ada for a project at work
>
> Excellent choice :).
>
> > and I have a question I hope someone can answer. If I am
> > interpreting the RM section 6.2 correctly, an array of elementary
> > types does not meet the criteria of a by-reference type.
>
> A 'by-reference type' is simply one that is always passed by
> reference, never by copy.
That's what I thought.
>
> > But, when looking at the disassembly, it seems that passing an array
> > of elementary types to a function as an in-mode parameter is passing
> > by reference. Does this mean that an array of elementary types is an
> > unspecfied type?
>
> The compiler is always free to choose either copy or reference for
> passing parameters.
This statement seems to contradict the RM and what you've said above.
The way I read the RM, a by-reference type is passed by reference. No
choice. A by-value type is passed by value. Again, no choice. The RM
seems to indicate that the only time a compiler is free to choose is
for the 'unspecified' types.
>
> I'm not clear what you mean by "unspecified type". Hmm, perhaps you
> are refering to 6.2(11):
>
> For parameters of other types, it is unspecified whether the
> parameter is passed by copy or by reference.
Exactly.
>
> Yes, an array of elementary types is an "other type" in this sense; it
> may be passed either by reference or copy. The compiler will choose
> whichever mechanism it feels is "best".
That's what I assumed when reading the RM. I'll play around with small
arrays and see if the compiler decides by-value is better.
>
> > A 2nd part to my question is: Does Ada automatically pass tagged types
> > by reference no matter what mode the parameter is specfied (in, in
> > out, or out)? The language RM 6.2 seems to suggest this is so.
>
> Yes.
>
> > If so, does this mean that there is no way to pass a tagged type by
> > value?
>
> Yes.
>
> > I believe C# works this way without programmer intervention.
>
> Don't know.
> A couple of larger questions;
>
> Why do you care whether a type is passed by copy or reference?
>
> If you are worried about time or space efficiency, specify the
> appropriate option to the compiler, and forget about it, until
> measurements of your final application show a problem.
>
> Why would you want to pass a tagged type by copy?
>
> You might want to read the Ada Rationale, and the annotated Ada
> Reference manual, on this topic. See
> http://www.adaic.com/standards/ada95.html
next prev parent reply other threads:[~2004-04-09 12:44 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-08 14:52 Pass by reference Dan McLeran
2004-04-08 18:21 ` Martin Krischik
2004-04-09 12:53 ` Dan McLeran
2004-04-13 12:42 ` Martin Krischik
2004-04-08 19:04 ` Jim Rogers
2004-04-09 3:24 ` Dan McLeran
2004-04-09 0:01 ` Stephen Leake
2004-04-09 12:38 ` Dan McLeran
2004-04-09 13:03 ` Dmitry A. Kazakov
2004-04-09 19:09 ` Dan McLeran
2004-04-10 10:49 ` Dmitry A. Kazakov
2004-04-11 12:43 ` Florian Weimer
2004-04-12 10:29 ` Dmitry A. Kazakov
2004-04-12 12:29 ` Samuel Tardieu
2004-04-13 8:46 ` Dmitry A. Kazakov
2004-04-10 1:42 ` Stephen Leake
2004-04-10 16:05 ` chris
2004-04-09 12:44 ` Dan McLeran [this message]
2004-04-09 22:44 ` Randy Brukardt
2004-04-09 14:44 ` Simon Wright
2004-04-09 1:15 ` Jeffrey Carter
2004-04-09 1:28 ` Pat Rogers
2004-04-10 1:05 ` Jeffrey Carter
2004-04-09 12:57 ` Dan McLeran
2004-04-10 1:16 ` Jeffrey Carter
2004-04-09 4:03 ` Steve
2004-04-09 14:50 ` Simon Wright
2004-04-09 17:12 ` Pat Rogers
2004-04-09 19:33 ` Vinzent 'Gadget' Hoefler
2004-04-10 6:33 ` Simon Wright
2004-04-13 10:26 ` Vinzent 'Gadget' Hoefler
2004-04-14 17:27 ` Simon Wright
2004-04-15 9:43 ` Vinzent 'Gadget' Hoefler
2004-04-17 7:59 ` Simon Wright
2004-04-11 12:45 ` Florian Weimer
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox