From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Access types as parameters
Date: Fri, 17 Jul 2009 20:03:12 -0500
Date: 2009-07-17T20:03:12-05:00 [thread overview]
Message-ID: <h3r726$q9t$1@munin.nbi.dk> (raw)
In-Reply-To: 8410fc60-9b8a-4f82-92fc-622a6bbe5931@i18g2000pro.googlegroups.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1836 bytes --]
"rickduley" <rickduley@gmail.com> wrote in message
news:8410fc60-9b8a-4f82-92fc-622a6bbe5931@i18g2000pro.googlegroups.com...
> I don't quite see what you mean by:
>
>> But this does not means � access My_Type'Class � is better beceause it
>> is � safer � (quotes, beceause the other way is not always not safe),
>> as sometime, My_Access_Type is mandatory, depending on what the
>> function have to do with the reference.
>
>If the function is called, and the actual parameter is valid, what
>difference can it make what the function does with the data?
He might be referring to the fact that the uses of the anonymous access
parameter might raise Program_Error (as there is a dynamic accessibility
check) while the named example is either going to be legal (and work
properly) or illegal.
My answer to the original question would have been:
>Given:
>
> type My_Type is ...;
>and
> type My_Access_Type is access all My_Type'Class;
>
>what is the practical difference between:
>
> function My_Function (Thing : access My_Type'Class) return Positive;
>and
> function My_Function (Thing : My Access_Type) return Positive;
The first has a runtime parameter passing overhead that the latter does not,
and depending on how the parameter is used inside of the function, a
significant possibility of raising Program_Error later. (Something Bob Duff
calls a "tripping hazard"). This latter problem is especially bad as it is
likely to be missed in unit testing (in that sense, it is similar to
assuming the lower bound of a string is 1 - tests often make the same
assumption).
So it is best to avoid the first form unless you have a particular need for
dispatching on an access value (which won't happen here, because the
designated type is class-wide).
Randy.
next prev parent reply other threads:[~2009-07-18 1:03 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-17 8:39 Access types as parameters Rick
2009-07-17 15:03 ` Adam Beneschan
2009-07-17 16:28 ` Hibou57 (Yannick Duchêne)
2009-07-17 23:25 ` rickduley
2009-07-18 1:03 ` Randy Brukardt [this message]
2009-07-19 22:57 ` rickduley
2009-07-20 0:10 ` John B. Matthews
2009-07-20 8:13 ` Dmitry A. Kazakov
2009-07-21 0:34 ` Randy Brukardt
2009-07-21 14:34 ` Adam Beneschan
2009-07-23 2:11 ` Stephen Leake
2009-08-11 23:41 ` Randy Brukardt
2009-08-12 2:22 ` Stephen Leake
2009-08-13 1:06 ` Randy Brukardt
2009-08-13 8:34 ` Niklas Holsti
2009-08-13 9:15 ` Dmitry A. Kazakov
2009-08-13 20:13 ` Niklas Holsti
2009-08-13 21:07 ` Dmitry A. Kazakov
2009-08-14 9:27 ` Niklas Holsti
2009-08-14 10:36 ` Dmitry A. Kazakov
2009-08-14 16:03 ` Niklas Holsti
2009-08-15 9:47 ` Dmitry A. Kazakov
2009-08-15 19:19 ` Niklas Holsti
2009-08-16 8:32 ` Dmitry A. Kazakov
2009-08-16 9:52 ` Niklas Holsti
2009-08-16 12:38 ` Dmitry A. Kazakov
2009-08-16 13:21 ` Niklas Holsti
2009-08-16 17:58 ` Dmitry A. Kazakov
2009-08-14 4:07 ` Randy Brukardt
2009-08-14 10:22 ` Niklas Holsti
2009-08-18 12:22 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox