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.3 required=5.0 tests=BAYES_00,HEADER_SPAM autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b30bd69fa8f63cb2 X-Google-Attributes: gid103376,public X-Google-Thread: fc772,b30bd69fa8f63cb2 X-Google-Attributes: gidfc772,public X-Google-ArrivalTime: 2003-06-15 14:57:40 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!uwm.edu!rpi!not-for-mail From: Ed Avis Newsgroups: comp.lang.ada,comp.lang.c++.moderated Subject: Re: C bug of the day Date: 15 Jun 2003 17:59:54 -0400 Organization: unknown Sender: cppmods@netlab.cs.rpi.edu Message-ID: References: <1054751321.434656@master.nyc.kbcfp.com> NNTP-Posting-Host: netlab.cs.rpi.edu X-Original-Date: 15 Jun 2003 17:55:14 +0100 X-Submission-Address: c++-submit@netlab.cs.rpi.edu X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated iQBVAwUAPuzsUEHMCo9UcraBAQGeqwH/TlWjPLt9WJuOROTF00CdbLW4hdIp7xvb 99ciqPQhbYFeWkQF2wMUEnF+LkN49O+EJwuyC8Rlu2hQl+u9zTjQWQ== =Rc15 Xref: archiver1.google.com comp.lang.ada:39211 comp.lang.c++.moderated:68415 Date: 2003-06-15T17:59:54-04:00 List-Id: LLeweLLyn writes: >>>>In Ada, GC is automatic for stack variables, >> >>>In C++ GC is automatic for stack variables as well >> int* f() >> { >> int x = 5; >> return &x; >> } >Ada has no more (and no less) garbage collection here than C++ >does. In both cases, stack variables are deallocated at the end of >the function or subprogram. What Ada does have is checked accesibilty >rules that prevent returning a pointer to a local object. I suppose this is a conservative analysis associating a scope level with each variable (as part of its type) and forbidding assignment or initialization (or whatever the equivalent Ada terms are) of a value to a variable not in the same scope or in a deeper scope. Does this check ever get in the way of expressing reasonable programs? Could not C and C++ have the same check? -- Ed Avis [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]