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:39:30 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!news.tufts.edu!uunet!dca.uu.net!ash.uu.net!world!news From: "Ben Brosgol" Subject: Re: Run-Time Type Assignment X-Mimeole: Produced By Microsoft MimeOLE V5.50.4522.1200 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: X-Priority: 3 Date: Thu, 29 Aug 2002 13:32:22 GMT X-Msmail-Priority: Normal References: <5ee5b646.0208280304.614d11fc@posting.google.com> NNTP-Posting-Host: ppp0c037.std.com Organization: The World @ Software Tool & Die X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 Xref: archiver1.google.com comp.lang.ada:28548 Date: 2002-08-29T13:32:22+00:00 List-Id: 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