From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,7ff1de84a8945e80 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!feeder.erje.net!nuzba.szn.dk!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Access types as parameters Date: Fri, 17 Jul 2009 20:03:12 -0500 Organization: Jacob Sparre Andersen Message-ID: References: <521c4843-d40f-4545-9e80-ca725e847090@h21g2000yqa.googlegroups.com> <8410fc60-9b8a-4f82-92fc-622a6bbe5931@i18g2000pro.googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1247879046 26941 69.95.181.76 (18 Jul 2009 01:04:06 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Sat, 18 Jul 2009 01:04:06 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5512 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 Xref: g2news2.google.com comp.lang.ada:7123 Date: 2009-07-17T20:03:12-05:00 List-Id: "rickduley" 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.