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-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) Date: 12 Mar 2005 09:16:26 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <1110284070.410136.205090@o13g2000cwo.googlegroups.com> <395uqaF5rhu2mU1@individual.net> <1110377260.350158.58730@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: shell01-e.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1110636987 29180 69.38.147.31 (12 Mar 2005 14:16:27 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sat, 12 Mar 2005 14:16:27 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:9233 comp.lang.c++:45294 comp.realtime:1365 comp.software-eng:4926 Date: 2005-03-12T09:16:26-05:00 List-Id: Pascal Obry writes: > This is not ok, P3 deeper than PA. > > << > procedure Demo is > > type PA is access procedure; > > procedure P (Proc : in PA) is > begin > null; > end P; > > procedure P1 is > begin > null; > end P1; > > procedure P2 is > procedure P3 is > begin > null; > end P3; > begin > P (P3'Access); > end P2; > > begin > null; > end Demo; > >> However, it will be legal to pass a nested procedure in Ada 2005, and GNAT already supports that. The rules still prevent dangling pointers: procedure P (Proc : access procedure(...)) is begin Proc; end P; procedure P2 is P2_Local: Integer := 0; procedure P3 is begin P2_Local := P2_Local + 1; end P3; begin P (P3'Access); end P2; In Pascal's example, P can assign Proc into a global variable, and it can be called after P2 returns, which is why it is forbidden to pass P3. In my example, on the other hand, you can pass P3, but P cannot assign Proc into a global variable. Either way, no dangling pointers, unless you play some low-level tricks. > > Can templates recurse? > > Yes. I think he meant "can generic instantiation be recursive", and the answer is "no, it cannot". A generic procedure can call itself, but that's not the same thing. > > Can you program "const correct"? Eg. if you declare a member function > > as const the compiler will help you not mutate the object or call any > > functions that do. Also, if you pass a parameter as a const reference, > > you will not be able to mutate the object the parameter references. > > Not sure to understand everything. But yes, if you have: > > Value : constant String := "whatever"; > > It will never be able to mutate Value. ... and 'in' mode parameters can't be modified, and you can't modify what an access-to-constant points at. I think it's a bit more difficult to "cast away const" in Ada, and the results can be bad news. - Bob