comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@acm.org>
To: comp.lang.ada@ada-france.org
Subject: Re: Is this a bug?
Date: 23 Sep 2004 20:28:13 -0400
Date: 2004-09-23T20:28:13-04:00	[thread overview]
Message-ID: <mailman.81.1095985702.390.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <sa4mzzg62qt.fsf@snoopy.apana.org.au>

Brian May <bam@snoopy.apana.org.au> writes:

> So another words, if I did the following:
> 
> declare
>    ...
>    Current : Bucket_Access renames Current_Hook.all;
> 
> begin
>    ...
>    Current_Hook := <something else>
>    ...
> end;
> 
> 
> Then Current would still be the same object and value it use to be?

Yes, you have it right.

> If so, then "renames" isn't quite as simple as I thought. 

You are not alone; it seems to be a common misunderstanding for people
learning Ada.

> It is more like a "hard link" then a "symbolic link". i.e. it links
> to the object rather then the name of the object. Interesting.

The purpose of "renames" is to cache the results of computing a
complex name. Although sometimes we think of it as just "cleaning up
the code", it can produce significant time and code space
optimization.

If you want a short name for a complex expression, that is re-evaluated
each time the name is used, you need a function, not a rename:

declare
    function Current is return Current_Hook.all; end Current;
begin

Only 3 more identifiers!

> Question: If you freed the value (with unchecked_deallocate) of
> "Current_Hook" would the value of "Current" still be valid? I
> suspect it would not be valid, as "Current" is now dangling. 

Current would be invalid.

-- 
-- Stephe




  reply	other threads:[~2004-09-24  0:28 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-23  0:52 Is this a bug? Wojtek Narczynski
2004-09-23  8:35 ` Wojtek Narczynski
2004-09-23 14:52   ` Nick Roberts
2004-09-23 22:26     ` Brian May
2004-09-24  0:28       ` Stephen Leake [this message]
2004-09-24  0:57         ` Jeffrey Carter
2004-09-24 12:47         ` Wojtek Narczynski
2004-09-25  0:17           ` Brian May
2004-09-24 12:37       ` Wojtek Narczynski
2004-09-23 11:27 ` Jeff C r e e.m
2004-09-24  0:30   ` Stephen Leake
2004-09-24  1:49     ` Jeff C r e e.m
2004-09-25 12:59       ` Stephen Leake
2004-10-04 16:36         ` Warren W. Gay VE3WWG
  -- strict thread matches above, loose matches on Subject: below --
2019-12-30 15:44 reinert
2019-12-30 17:51 ` Anh Vo
2019-12-30 18:41   ` Niklas Holsti
2019-12-30 19:50     ` reinert
2019-12-30 20:11       ` Dmitry A. Kazakov
2019-12-30 23:16     ` Randy Brukardt
2019-12-31 19:40       ` Optikos
2019-12-31 21:50         ` Randy Brukardt
2020-01-02  9:34           ` Dmitry A. Kazakov
2020-01-03  7:26             ` reinert
2020-01-03  7:35             ` reinert
2020-01-03  8:37               ` Dmitry A. Kazakov
2020-01-04  0:42                 ` Randy Brukardt
2020-01-05 13:32                   ` reinert
2020-01-06 10:43                     ` J-P. Rosen
2020-01-06 12:19                       ` Tero Koskinen
2020-01-17  9:54                 ` reinert
2020-01-17 10:08                   ` Dmitry A. Kazakov
2020-01-17 22:14                   ` Randy Brukardt
2019-12-31  6:08     ` J-P. Rosen
replies disabled

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