From: matthew_heaney@acm.org (Matthew Heaney)
Subject: Re: Q:Assigning address of variable to pointer ?
Date: 1998/04/16
Date: 1998-04-16T00:00:00+00:00 [thread overview]
Message-ID: <matthew_heaney-ya023680001604980057320001@news.ni.net> (raw)
In-Reply-To: Pine.BSI.3.95.980415115344.24305B-100000@school.digsys.bg
In article <Pine.BSI.3.95.980415115344.24305B-100000@school.digsys.bg>,
Margarit Nickolov <man@digsys.bg> wrote:
> type element is record
> ...
> end record;
>
> type p_element is access element;
>
> e1: element;
> p_e1: p_element := null;
>
> begin
> e1 := some_value;
> -- now, how to point p_e1 to the variable e1 ?
> p_e1.all := e1; -- is that correct ?
> -- I have got exception RANGE_ERROR.
> end;
>
>
> I just want to assign 'address' of some dynamic/static allocated memory to
>'pointer variable'.
You have to declare the object you want to point to as aliased - but
declare a general access type:
type p_element is access all element;
declare
e1 : aliased element;
p_e1 : p_element;
begin
e1 := <some value>;
p_e1 := e1'access;
end;
Of course, you could always put the object on the heap:
declare
e1 : element;
p_e1 : p_element;
begin
e1 := <some value>;
p_e1 := new element;
p_e1.all := e1;
end;
And we can combine steps:
declare
p_e1 : constant p_element := new element'(<some value>);
begin
null;
end;
next prev parent reply other threads:[~1998-04-16 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-04-16 0:00 Q:Assigning address of variable to pointer ? Margarit Nickolov
1998-04-16 0:00 ` Matthew Heaney [this message]
1998-04-16 0:00 ` Steve Doiel
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox