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 02:59:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!uwm.edu!rpi!not-for-mail From: LLeweLLyn Newsgroups: comp.lang.ada,comp.lang.c++.moderated Subject: Re: C bug of the day Date: 15 Jun 2003 06:01:22 -0400 Organization: The Illusory Sorting Algorithm 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: Sat, 14 Jun 2003 19:14:13 -0600 X-Submission-Address: c++-submit@netlab.cs.rpi.edu X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated iQBVAwUAPuxD7kHMCo9UcraBAQGZPAH/eYXOyw6sJYwqh9Dw3j3n/UeByFYF9Cdm 9eMefh15HgOFPwfW6OvFqc44ipMCUakyJ4WdZuwdNWlSzAzOYQfXHw== =TYGf Xref: archiver1.google.com comp.lang.ada:39192 comp.lang.c++.moderated:68385 Date: 2003-06-15T06:01:22-04:00 List-Id: Ed Avis writes: > LLeweLLyn writes: > >>>In Ada, GC is automatic for stack variables, > >>In C++ GC is automatic for stack variables as well > > I think this is abusing the term 'garbage collection', consider: > > int* f() > { > int x = 5; > return &x; > } As far as I can see, I abused the term 'garbage collection' exactly as much as Wesley did. 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. > > If C++ really did have garbage collection for stack variables, then x > would not be destroyed on exit from the function since there is still > a live pointer to it. What C++ has is something much cruder - any > stack variable is destroyed on exit from the scope it was declared in. > > You could say 'C++ does have garbage collection for stack variables, > you're just not allowed to return pointers or references to them', but > that amounts to the same thing. Yes. And it amounts to being equivalent to Wesley's statement. [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ] [ about comp.lang.c++.moderated. First time posters: do this! ]