comp.lang.ada
 help / color / mirror / Atom feed
* Self-referential 'Access
@ 1998-04-20  0:00 Stanley Allen
  1998-04-20  0:00 ` Tucker Taft
  1998-04-20  0:00 ` Matthew Heaney
  0 siblings, 2 replies; 4+ messages in thread
From: Stanley Allen @ 1998-04-20  0:00 UTC (permalink / raw)



For the language lawyers:

Below is a library-level package spec that
I have tried to compile with both GNAT (3.10p)
and ObjectAda (7.1) on my Win95/AMD586 box.

------------ cellar.ads -----------
package Cellar is

    type Cell;

    type List is access all Cell;

    type Cell is limited record
        Contents : String (1 .. 10);
        Next_Cell : List := Cell'Access;  --line 9
        Prev_Cell : List := Cell'Access;  --line 10
    end record;

end Cellar;
-----------------------------------

Both compilers claim that the uses of the
'Access attribute are not valid because they
violate the rules concerning depth of
accessability.

GNAT says this:
    cellar.ads:9:29 object has deeper accessibility
    level than access type
    [and the same for line 10]

ObjectAda says:
    cellar.ads: Error: line 9 col 29 LRM:3.10.2(28),
        The prefix to 'ACCESS shall not be statically
        deeper than that of the expected type
    [and the same for line 10]

(Note: I have not attempted to declare a Cell
object in any other unit; the errors are generated
strictly from the compilation of this package spec.)

The rules for "statically deeper" levels are given
under RM95:3.10.2(17).  The only rule that seems
like it might apply here is RM95:3.10.2(21).

So, I have a few questions.

1) Are the compilers in error, or is this code?

2) If this code is in error, is it because of the
   rule at paragraph (21)?

3) If so, does this rule really make sense?
   It does not seem right that these 'Access
   references should be considered "deeper" than
   the access type.

4) Should the rule disallow only non-limited
   records?

Stanley Allen
mailto:sallen@ghg.net




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

* Re: Self-referential 'Access
  1998-04-20  0:00 Self-referential 'Access Stanley Allen
  1998-04-20  0:00 ` Tucker Taft
@ 1998-04-20  0:00 ` Matthew Heaney
  1998-04-20  0:00   ` Jerry van Dijk
  1 sibling, 1 reply; 4+ messages in thread
From: Matthew Heaney @ 1998-04-20  0:00 UTC (permalink / raw)



In article <353B4DC4.EB3650F4@ghg.net>, Stanley Allen <sallen@ghg.net> wrote:

(start of quote)
------------ cellar.ads -----------
package Cellar is

    type Cell;

    type List is access all Cell;

    type Cell is limited record
        Contents : String (1 .. 10);
        Next_Cell : List := Cell'Access;  --line 9
        Prev_Cell : List := Cell'Access;  --line 10
    end record;

end Cellar;
-----------------------------------

Both compilers claim that the uses of the
'Access attribute are not valid because they
violate the rules concerning depth of
accessability.
(end of quote)

I don't know the exact rules here, but what I do in cases like this is just
use Unchecked_Access:

    type Cell is limited record
        Contents : String (1 .. 10);
        Next_Cell : List := Cell'Unchecked_Access;
        Prev_Cell : List := Cell'Unchecked_Access;
    end record;

This compiles cleanly using GNAT 3.10p.




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

* Re: Self-referential 'Access
  1998-04-20  0:00 Self-referential 'Access Stanley Allen
@ 1998-04-20  0:00 ` Tucker Taft
  1998-04-20  0:00 ` Matthew Heaney
  1 sibling, 0 replies; 4+ messages in thread
From: Tucker Taft @ 1998-04-20  0:00 UTC (permalink / raw)



Stanley Allen (sallen@ghg.net) wrote:

: ...
: The rules for "statically deeper" levels are given
: under RM95:3.10.2(17).  The only rule that seems
: like it might apply here is RM95:3.10.2(21).

: So, I have a few questions.

: 1) Are the compilers in error, or is this code?

The code is in error.

: 2) If this code is in error, is it because of the
:    rule at paragraph (21)?

Yes.

: 3) If so, does this rule really make sense?
:    It does not seem right that these 'Access
:    references should be considered "deeper" than
:    the access type.

The problem is that you are creating a value of a named access type.  
It is true that storing such references inside the object itself will 
not cause trouble.  But because the access type is named, there is nothing
precluding your copying their value into some other object
of the same access type, with no further accessibility check.
It is quite possible that that object might outlive the limited
record object.

: 4) Should the rule disallow only non-limited
:    records?

The rule as written in justifiable, because there are no
further checks when you copy the value from an object having a named 
access type.

As pointed out in another response, you can use 'Unchecked_Access
to bypass the check.  You must still be careful not to copy
the components into global variables that outlive the limited record object.

: Stanley Allen
: mailto:sallen@ghg.net

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




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

* Re: Self-referential 'Access
  1998-04-20  0:00 ` Matthew Heaney
@ 1998-04-20  0:00   ` Jerry van Dijk
  0 siblings, 0 replies; 4+ messages in thread
From: Jerry van Dijk @ 1998-04-20  0:00 UTC (permalink / raw)



I guess this is an opertunity to learn something as:

Matthew Heaney (matthew_heaney@acm.org) wrote:

: I don't know the exact rules here, but what I do in cases like this is just
: use Unchecked_Access:

:     type Cell is limited record
:         Contents : String (1 .. 10);
:         Next_Cell : List := Cell'Unchecked_Access;
:         Prev_Cell : List := Cell'Unchecked_Access;
:     end record;

: This compiles cleanly using GNAT 3.10p.

As Cell is a type, not an object, what are Next_Cell and
Prev_Cell initialized to here ?

Jerry.

-- 
-- Jerry van Dijk  | email: jdijk@acm.org
-- Leiden, Holland | member Team-Ada




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

end of thread, other threads:[~1998-04-20  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-20  0:00 Self-referential 'Access Stanley Allen
1998-04-20  0:00 ` Tucker Taft
1998-04-20  0:00 ` Matthew Heaney
1998-04-20  0:00   ` Jerry van Dijk

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