comp.lang.ada
 help / color / mirror / Atom feed
* OUT = IN OUT for pointers ???
@ 2001-11-06 23:58 Pi
  2001-11-08 14:12 ` Marc A. Criley
  0 siblings, 1 reply; 3+ messages in thread
From: Pi @ 2001-11-06 23:58 UTC (permalink / raw)


I came across some code where a pointer was passed in mode OUT.
If the pointer would be null initially, the code wouldn't work.

But it does work.

With a debugger I verified :
Even as the pointer is in mode OUT,
it's value is passed as if it was IN OUT.

I use GNAT, but Aonix seams to have the same behavior too.

Now, my question :
Must it be like that and is defined that way in the ARM ?
or it is an option that it left to the choice of the implementation ?
or is it a bug ?

-- 
3,14159265359



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

* Re: OUT = IN OUT for pointers ???
  2001-11-06 23:58 OUT = IN OUT for pointers ??? Pi
@ 2001-11-08 14:12 ` Marc A. Criley
  2001-11-08 17:46   ` Jeffrey Carter
  0 siblings, 1 reply; 3+ messages in thread
From: Marc A. Criley @ 2001-11-08 14:12 UTC (permalink / raw)


Pi wrote:
> 
> I came across some code where a pointer was passed in mode OUT.
> If the pointer would be null initially, the code wouldn't work.
> 
> But it does work.
> 
> With a debugger I verified :
> Even as the pointer is in mode OUT,
> it's value is passed as if it was IN OUT.
> 
> I use GNAT, but Aonix seams to have the same behavior too.
> 
> Now, my question :
> Must it be like that and is defined that way in the ARM ?
> or it is an option that it left to the choice of the implementation ?
> or is it a bug ?

It kinda depends on the code where this is occurring.  Generally, an
'out' mode parameter is to be treated as an uninitialized local
variable, meaning that it could contain any sequence of bits--which may
or may not designate a valid value.

Since a compiler will commonly pass an out parameter as (in effect) the
address of the argument, an initial value possessed by that argument may
be unintentionally made available to the subprogram body.  Depending on
and using such a value, however, is erroneous.

Note, though, that some kinds of information can be legally extracted
from certain kinds of types of arguments passed as out paramters, e.g.,
the bounds of an array, the value of a record discriminant.

Marc A. Criley
Senior Staff Engineer
Quadrus Corporation
www.quadruscorp.com



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

* Re: OUT = IN OUT for pointers ???
  2001-11-08 14:12 ` Marc A. Criley
@ 2001-11-08 17:46   ` Jeffrey Carter
  0 siblings, 0 replies; 3+ messages in thread
From: Jeffrey Carter @ 2001-11-08 17:46 UTC (permalink / raw)


"Marc A. Criley" wrote:
> 
> It kinda depends on the code where this is occurring.  Generally, an
> 'out' mode parameter is to be treated as an uninitialized local
> variable, meaning that it could contain any sequence of bits--which may
> or may not designate a valid value.

There are important exceptions to this, see ARM 6.4.1.

Of interest to this question, 6.4.1(7) says

"For an out parameter that is passed by copy ...: For an access type,
the formal parameter is initialized from the value of the actual,
without a constraint check"

For pass-by-reference types, types with discriminants, and types with
implicit initial values, there is no difference between mode out and
mode in out. Mode out can be relied on to be significantly different
from mode in out only for numeric and enumeration types.

> 
> Since a compiler will commonly pass an out parameter as (in effect) the
> address of the argument, an initial value possessed by that argument may
> be unintentionally made available to the subprogram body.  Depending on
> and using such a value, however, is erroneous.

However, elementary types, which include access types, are always passed
by copy.

-- 
Jeffrey Carter



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

end of thread, other threads:[~2001-11-08 17:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-06 23:58 OUT = IN OUT for pointers ??? Pi
2001-11-08 14:12 ` Marc A. Criley
2001-11-08 17:46   ` Jeffrey Carter

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