comp.lang.ada
 help / color / mirror / Atom feed
* Parameters in Sub
@ 2001-09-21 15:13 Marc
  0 siblings, 0 replies; 3+ messages in thread
From: Marc @ 2001-09-21 15:13 UTC (permalink / raw)


Hello,
I will want to know: modes OUT and IN OUT, in a procedure, show all the 2
clearly a passage of parameters by " address " (of the variable). I have a
doubt about what one call the passage " by reference "
I associated it  IN OUT has this type of passage. Is this well that. Then
the passage by " value " designe it IN, the passage by " address " designe
the OUT??? Thank you for your answers.





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Parameters in Sub
@ 2001-09-21 16:37 Ted Dennison
  2001-09-21 18:28 ` Jeffrey Carter
  0 siblings, 1 reply; 3+ messages in thread
From: Ted Dennison @ 2001-09-21 16:37 UTC (permalink / raw)


In article <9ofn8h$m0v$1@reader1.fr.uu.net>, Marc says...
>
>Hello,
>I will want to know: modes OUT and IN OUT, in a procedure, show all the 2
>clearly a passage of parameters by " address " (of the variable). I have a
>doubt about what one call the passage " by reference "
>I associated it  IN OUT has this type of passage. Is this well that. Then
>the passage by " value " designe it IN, the passage by " address " designe
>the OUT??? Thank you for your answers.

This is a bit hard to decipher, but it looks like you are asking when/if "OUT"
and "IN OUT" use reference passing, and when they use value. The quick answer is
"it depends".

A slightly more complete answer is that there are some situations where the
language specifies reference passing, but in all other situations it is up to
the compiler. In those cases you can trust that the compiler will do what is
most efficient (eg: reference whenever the value would be too big to fit in a
register), but you *must* not make your code depend on the mode by taking
addresses of parameters or assuming two parameters of the same type are
different objects. 

For a complete answer, I suggest you either read the relevant LRM sections or
get a good Ada book that covers this subject. There are some situations where it
is useful to know which is done. But if you are an Ada beginner, the best rule
is to just assume that the compiler knows what it is doing, and do not write
your code in such a way that proper operation depends on one method or the
other. Whatever you do, do *not* look to pass around addresses with the
misguided assumption that it will be quicker.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Parameters in Sub
  2001-09-21 16:37 Parameters in Sub Ted Dennison
@ 2001-09-21 18:28 ` Jeffrey Carter
  0 siblings, 0 replies; 3+ messages in thread
From: Jeffrey Carter @ 2001-09-21 18:28 UTC (permalink / raw)


Ted Dennison wrote:
> 
> A slightly more complete answer is that there are some situations where the
> language specifies reference passing, but in all other situations it is up to
> the compiler. 

This is not completely correct (see ARM 6.2). Elementary types (such as
integral and real types) are always passed by copy. Tagged types and
limited types are always passed by reference, as are composite types
with a component that must be passed by reference. Other types do not
have their passing mechanisms specified; it is up to the compiler to
decide.

I think the original poster was attempting to equate parameter modes
with parameter passing mechanisms. This is a common mistake for Ada
beginners who know languages in which the coder specifies the passing
mechanism (such as Pascal).

The original poster should become aware that there is no relationship
between the parameter mode (in, in out, or out) and the parameter
passing mechanism. The parameter mode is a high-level specification of
how the parameter is used by the subprogram.

-- 
Jeffrey Carter



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-09-21 18:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-21 16:37 Parameters in Sub Ted Dennison
2001-09-21 18:28 ` Jeffrey Carter
  -- strict thread matches above, loose matches on Subject: below --
2001-09-21 15:13 Marc

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