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 07:56:38 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: Robert A Duff Subject: Re: Run-Time Type Assignment Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Thu, 29 Aug 2002 14:56:07 GMT References: <5ee5b646.0208280304.614d11fc@posting.google.com> NNTP-Posting-Host: shell01.theworld.com Organization: The World Public Access UNIX, Brookline, MA X-Newsreader: Gnus v5.7/Emacs 20.7 Xref: archiver1.google.com comp.lang.ada:28555 Date: 2002-08-29T14:56:07+00:00 List-Id: "Ben Brosgol" writes: > 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. Yeah, and array indexing in C is just as safe as in Ada -- so long as you don't index outside the array bounds. Driving 120 miles per hour in a 30 mph zone without wearing a seat belt is perfectly safe -- so long as you don't cause a collision. OK, sorry for infamatory rhetoric, Ben, but claiming that 'Unrestricted_Access is as safe as in Pascal is just plain silly. The fact is, you can accidentally create dangling pointers using 'Unrestricted_Access, which you can't do by passing procedural parameters in Pascal. >...(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 Well, it's nice that it detects *some* errors (it detects misspellings like 'Unrestricted_Acess, too!), but it doesn't detect dangling pointers. > declare > procedure Q is begin null; end Q; > begin > Ref := Q'Unrestricted_Access; -- OK That's the problem (the above "OK"). If you call Ref.all later, you're in trouble. GNAT thinks it's OK, but it is *not* 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? :-) I see the smiley, but, for example, the company I work for (SofCheck, Inc.) produces Ada compilers for targets that GNAT does not support. And we've recently heard Robert Dewar pointing out that ACT is not attempting to cover the *entire* Ada business -- quite reasonably, ACT has a narrower focus, as do other vendors. - Bob