comp.lang.ada
 help / color / mirror / Atom feed
* Puzzling question
@ 1997-05-08  0:00 Chris Sparks (Mr. Ada)
  1997-05-08  0:00 ` Adam Beneschan
  1997-05-10  0:00 ` Robert Dewar
  0 siblings, 2 replies; 3+ messages in thread
From: Chris Sparks (Mr. Ada) @ 1997-05-08  0:00 UTC (permalink / raw)



Hi all,

I have the following files:

----------------------------------------------------------------------
package T is

  type Rec_Type is record
    A : Integer;
    B : Integer;
  end record;

  procedure S (U : out Rec_Type);

end T;
----------------------------------------------------------------------
with System;

package body T is

  procedure R (V : in System.Address) is begin

    null;

  end R;

  procedure S (U : out Rec_Type) is begin

    U.A := 1;
    U.B := 2;

    R (V => U.A'Address);  -- Why is this valid????????????????

  end S;

end T;
----------------------------------------------------------------------
with T; use T;

procedure T1 is

  M : Rec_Type;

begin
  T.S (U => M);
end;
----------------------------------------------------------------------

At work we are using Ada 83 and I thought that if a parameter is "out"
in a procedure then only assignments could be made to the variable.
In the call to R above, U.A would effectively be considered an input
which I thought would be illegal since U is an "out" type.  I know that
in Ada 95 this is ok, however, I don't know why this works under Ada 83.

Any help will be appreciated.

Chris Sparks




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

* Re: Puzzling question
  1997-05-08  0:00 Puzzling question Chris Sparks (Mr. Ada)
@ 1997-05-08  0:00 ` Adam Beneschan
  1997-05-10  0:00 ` Robert Dewar
  1 sibling, 0 replies; 3+ messages in thread
From: Adam Beneschan @ 1997-05-08  0:00 UTC (permalink / raw)



"Chris Sparks (Mr. Ada)" <sparks@AISF.COM> writes:
 
 >with System;
 >
 >package body T is
 >
 >  procedure R (V : in System.Address) is begin
 >
 >    null;
 >
 >  end R;
 >
 >  procedure S (U : out Rec_Type) is begin
 >
 >    U.A := 1;
 >    U.B := 2;
 >
 >    R (V => U.A'Address);  -- Why is this valid????????????????
 >
 >  end S;
 >
 >end T;

6.2(5) says "Reading the bounds and discriminants of the formal
parameter and of its subcomponents is allowed, but no other reading."

I don't know whether "reading" is defined explicitly in the Ada83 RM,
but I would suspect that taking the 'ADDRESS of a parameter is not
considered "reading".

                                -- Adam




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

* Re: Puzzling question
  1997-05-08  0:00 Puzzling question Chris Sparks (Mr. Ada)
  1997-05-08  0:00 ` Adam Beneschan
@ 1997-05-10  0:00 ` Robert Dewar
  1 sibling, 0 replies; 3+ messages in thread
From: Robert Dewar @ 1997-05-10  0:00 UTC (permalink / raw)



Chris asks

    R (V => U.A'Address);  -- Why is this valid????????????????

why not? I can't see anything in the Ada 83 that suggests that this 
would be illegal. Address can be applied to objects, and U.A is an
object. Now note that often applying address to parameters can give
totally meaningless results, or at the best implementation dependent
results, but address is ID anyway, so this is not really an issue.

<<At work we are using Ada 83 and I thought that if a parameter is "out"
  in a procedure then only assignments could be made to the variable.
  In the call to R above, U.A would effectively be considered an input
  which I thought would be illegal since U is an "out" type.  I know that
  in Ada 95 this is ok, however, I don't know why this works under Ada 83.>>

Why is U.A'Address "effectively" considered as an input, nothing is
being read! Ada 83 and Ada 95 are identical here, the fact that in one
you could write U.A is totally irrelevant.





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

end of thread, other threads:[~1997-05-10  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-08  0:00 Puzzling question Chris Sparks (Mr. Ada)
1997-05-08  0:00 ` Adam Beneschan
1997-05-10  0:00 ` Robert Dewar

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