comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Access types and classwide programming
Date: Sun, 16 Sep 2001 09:32:13 GMT
Date: 2001-09-16T09:32:13+00:00	[thread overview]
Message-ID: <xk_o7.13593$L%5.11076863@news1.rdc1.sfba.home.com> (raw)
In-Reply-To: 09Oo7.12082$mj6.1852826@news6-win.server.ntlworld.com

> procedure test_x is
>
>     temp : aliased xxx;
>
> begin
>     init (temp);    -- this is ok!
>
>     put( get_something(temp'access)); -- error 1 here
> end x;
>
> error 1 is "non-local pointer cannot point to local object"
  Suppose function get_something put a copy of its parameter into a
global variable.  After exiting text_x, that global would be a pointer
to ???  Thus the error message.  There are two solutions: define
get_something to take as parameter a type which is declared inside
of text_x, in which case clearly no global could exist for get_something
to set, or else else temp'unchecked_access, thus telling the compiler
"I know this is dangerous but I've looked carefully and it's OK here".

> What I want to do is to have a variable of type xxx and to pass it to
> get_something and to init.
  The "init" case already works fine.  Why not change get_something to
    function get_something (sc : in xxx'class)
    return integer;
thus getting rid of the access type and the problem.

Suppose you have a tagged type ttype, and need an access type to ttype and
it's class.

> type ttype is tagged ...;
> type ttype_access is access all ttype;
> typ ttype_caccess is access all ttype'class;  -- [surely you meant this]
>
> How do you
>
> a) get "access" to a variable of ttype?
  x : aliased ttype;
  p : ttype_access;
  ...
  p := x'access;
  p := new ttype;

> b) create a new instance of a ttype which is pointed to by a variable of
> type ttype_caccess?
  y : aliased ttype;
  p : ttype_caccess;
  ...
  p := x'access;
  p := new ttype;



  parent reply	other threads:[~2001-09-16  9:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-15 19:36 Access types and classwide programming chris.danx
2001-09-15 20:28 ` chris.danx
2001-09-15 23:42 ` [Different Topic] Endianess? chris.danx
2001-09-16  6:22   ` Jeffrey Carter
2001-09-17  7:37   ` Juanma Barranquero
2001-09-17  7:53     ` Assigning the value of a deferred constant? Juanma Barranquero
2001-09-17 14:04       ` Ted Dennison
2001-09-17 14:36         ` Juanma Barranquero
2001-09-17 17:36           ` tmoran
2001-09-18  8:16             ` Juanma Barranquero
2001-09-18 18:40         ` Richard Riehle
2001-09-19  2:07           ` Vincent Marciante
2001-09-19  7:39           ` Juanma Barranquero
2001-09-16  6:19 ` Access types and classwide programming Jeffrey Carter
2001-09-16 13:37   ` chris.danx
2001-09-16 16:49     ` Jeffrey Carter
2001-09-16 18:24       ` David C. Hoos, Sr.
2001-09-17  6:15         ` Jeffrey Carter
2001-09-17  4:57     ` tmoran
2001-09-17 14:16       ` Ted Dennison
2001-09-16  9:32 ` tmoran [this message]
2001-09-17  9:41 ` John McCabe
replies disabled

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