comp.lang.ada
 help / color / mirror / Atom feed
* Ada 9X question: accessibility
@ 1994-11-11 19:47 There can be only one
  1994-11-14 23:57 ` Tucker Taft
  0 siblings, 1 reply; 3+ messages in thread
From: There can be only one @ 1994-11-11 19:47 UTC (permalink / raw)


I was reading over the Ada 9X Reference Manual section on Access Types and
wanted to make sure I understood "accessibility" correctly.  I would appreciate 
any comments/confirmation on the following:


procedure Example is

   type Access_Integer_Type is access all Integer;
   Ptr_1  : Access_Integer_Type;
   Int_1  : aliased Integer;

begin
   Local_Block:
   declare
      Ptr_2  : Access_Integer_Type;
      Int_2  : aliased Integer;
   begin
      Ptr_1 := Int_1'Access; -- Legal.
      Ptr_1 := Int_2'Access; -- Illegal.
      Ptr_2 := Int_1'Access; -- Legal?
      Ptr_2 := Int_2'Access; -- Illegal?
   end Local_Block;
end Example;

As I understand it, the first assignment statement is legal, but the second one
is not because Int_2 is not dynamically accessible from the access type
Access_Integer_Type (and it's pretty obvious this would leave a dangling
reference).  What about the last two assignment statements?

Thanks in advance for your comments/help.

   
                             |         |
David Papay                  |    o    | 
papay@acm.org  (preferred)   |  ^/---  | <insert your favorite disclaimer here>
dpapay@aol.com (alternate)   |  />     |
                             |         |
                             | fleche! |



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

* Re: Ada 9X question: accessibility
  1994-11-11 19:47 Ada 9X question: accessibility There can be only one
@ 1994-11-14 23:57 ` Tucker Taft
  1994-11-15 13:57   ` Norman H. Cohen
  0 siblings, 1 reply; 3+ messages in thread
From: Tucker Taft @ 1994-11-14 23:57 UTC (permalink / raw)


In article <3a0hob$h5f@hopper.acm.org>,
There can be only one <papay@ACM.ORG> wrote:
>I was reading over the Ada 9X Reference Manual section on Access Types and
>wanted to make sure I understood "accessibility" correctly.  
>I would appreciate any comments/confirmation on the following:

We have recently rewritten this part of the manual in terms
of "levels" to try to make it more "accessible" ;-).
It was certainly pretty inscrutable in version 5.0.

>procedure Example is
>
>   type Access_Integer_Type is access all Integer;
>   Ptr_1  : Access_Integer_Type;
>   Int_1  : aliased Integer;
>
>begin
>   Local_Block:
>   declare
>      Ptr_2  : Access_Integer_Type;
>      Int_2  : aliased Integer;
>   begin
>      Ptr_1 := Int_1'Access; -- Legal.
>      Ptr_1 := Int_2'Access; -- Illegal.
>      Ptr_2 := Int_1'Access; -- Legal?

Legal.

>      Ptr_2 := Int_2'Access; -- Illegal?

Illegal.  It makes no difference where Ptr_2 is declared,
what matters is where the access type is declared.

If you had declared another access type inside the declare
block, and declared Ptr_3 to be of that type, then

   Ptr_3 := Int_2'Access;

would be legal.

>   end Local_Block;
>end Example;
>
>As I understand it, the first assignment 
>statement is legal, but the second one
>is not because Int_2 is not dynamically accessible from the access type
>Access_Integer_Type (and it's pretty obvious this would leave a dangling
>reference).  What about the last two assignment statements?

As you guessed, it makes no difference where Ptr_2 is declared,
what matters is where its type is declared.  In the new terminology,
the accessibility level of Int_2 is statically deeper than
the accessibility level of Access_Integer_Type, so the 'Access
is illegal.

>Thanks in advance for your comments/help.
>
>   
>                             |         |
>David Papay                  |    o    | 
>papay@acm.org  (preferred)   |  ^/---  |
>dpapay@aol.com (alternate)   |  />     |
>                             |         |
>                             | fleche! |

S. Tucker Taft   stt@inmet.com
Ada 9X Mapping/Revision Team
Intermetrics, Inc.
Cambridge, MA  02138



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

* Re: Ada 9X question: accessibility
  1994-11-14 23:57 ` Tucker Taft
@ 1994-11-15 13:57   ` Norman H. Cohen
  0 siblings, 0 replies; 3+ messages in thread
From: Norman H. Cohen @ 1994-11-15 13:57 UTC (permalink / raw)


In article <CzA7v5.KIJ@inmet.camb.inmet.com>, stt@spock.camb.inmet.com
(Tucker Taft) writes: 

|> As you guessed, it makes no difference where Ptr_2 is declared,
|> what matters is where its type is declared.  In the new terminology,
|> the accessibility level of Int_2 is statically deeper than
|> the accessibility level of Access_Integer_Type, so the 'Access
|> is illegal.

It would be helpful to explain why the rule must be based on the depth of
the variable's type rather than on the depth of the variable itself:  A
value stored in a local variable of a global access type can be assigned
to a global variable of the same type, thus creating a dangling
reference.

     procedure Example is
        type Outer_Access_Type is access all Integer;
        Outer_Variable: Outer_Access_Type;
     begin
        declare
           Inner_Variable : Outer_Access_Type;
           Target         : aliased Integer;
        begin
           Inner_Variable := Target'Access;  -- ILLEGAL!
           Outer_Variable := Inner_Variable;
        end;
        Outer_Variable.all := Outer_Variable.all + 1;  -- dangling reference
     end Example;

--
Norman H. Cohen    ncohen@watson.ibm.com



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

end of thread, other threads:[~1994-11-15 13:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-11-11 19:47 Ada 9X question: accessibility There can be only one
1994-11-14 23:57 ` Tucker Taft
1994-11-15 13:57   ` Norman H. Cohen

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