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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,330ec86e1824a689 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-08-29 06:49:30 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!skynet.be!skynet.be!freenix!teaser.fr!alecto.grec.isp.9tel.net!setranews.setra.fr!not-for-mail From: SIMON Claude Newsgroups: comp.lang.ada Subject: Re: Run-Time Type Assignment Date: Thu, 29 Aug 2002 15:52:27 +0200 Organization: S.E.T.R.A. Message-ID: <3D6E271B.538FDF52@equipement.gouv.fr> References: <5ee5b646.0208280304.614d11fc@posting.google.com> NNTP-Posting-Host: calamar.setra.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: setranews.setra.fr 1030628963 17066 161.48.101.33 (29 Aug 2002 13:49:23 GMT) X-Complaints-To: usenet@setranews.setra.fr NNTP-Posting-Date: 29 Aug 2002 13:49:23 GMT X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:28549 Date: 2002-08-29T13:49:23+00:00 List-Id: Does a "limited access procedure" could be THE solution ? Claude Simon Ben Brosgol wrote: > > Bob Duff wrote: > > > > > GNAT supports downward closures via the 'Unrestricted_Access > attribute, > > > > but that's not Ada (unfortunately). > > > > > > What about using just the plain old 'Access attribute to pass a pointer > to > > > the procedure as a parameter? That is supported by all Ada 95 compilers. > > > > No, 'Access doesn't work. Typically, the loop body (the procedure to be > > passed as a parameter) is more nested than the iterator, which makes > > 'Access illegal. > ... snip ... > > GNAT's 'Unrestricted_Access attribute works in this case, but it is > > nonportable and dangerous. The question was whether Pascal supports > > features not supported by Ada: in this case, it does; the feature is > > portable and safe (compared to 'Unrestricted_Access). > > The reason it is safe to pass nested subprograms as parameters in Pascal is > that Pascal does not allow subprograms to be used as values for variables or > placed in data structures. GNAT's 'Unrestricted_Access is just as safe, > provided that you abide by the Pascal restrictions. (I.e., > Unrestricted_Access still entails the other checks required by the language; > e.g. static subtype conformance for corresponding formals, matching > conventions.) For example: > > procedure Test_Unrestricted_Access is > type Acc is access procedure; > Ref : Acc; > procedure P1(N : Integer) is begin null; end P1; > procedure P2; > pragma Convention(C, P2); > procedure P2 is begin null; end P2; > begin > Ref := P1'Unrestricted_Access; -- error > Ref := P2'Unrestricted_Access; -- error > declare > procedure Q is begin null; end Q; > begin > Ref := Q'Unrestricted_Access; -- OK > Ref := Q'Access; --error > end; > end Test_Unrestricted_Access; > > The lines indicated by the "-- error" comments were diagnosed as > compile-time errors by GNAT. > > As for portability, if you are using GNAT why would you ever want to move to > some other compiler? :-) > > Ben Brosgol > Ada Core Technologies