Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Lexical Variables In C Loops (As Compared To Perl Loops) Date: Thu, 26 Mar 2015 23:38:48 -0700 Organization: None to speak of Lines: 24 Message-ID: <877fu3ndvr.fsf@kst-u.example.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="c77ff4d35e33d1c939d3461ebde8dd0d"; logging-data="23889"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195YWowjnExWNpYFrAoTQHo" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:z1x6RhM815fXKMELKZBbbYTgMlk= sha1:sJNZJavpi63YVetVrEhT5p4CfVQ= Xref: csiph.com comp.lang.c:59064 Robbie Hatley writes: [...] > Perl is ref-counted, so if you repeatedly alter a variable, save > a reference, alter the variable, save a reference, etc, during a > loop, then multiple "snapshots" of the variable will be created. > When the loop exists, the variable goes out of scope. BUT, the > snapshots remain, and the references you saved all point towards > those valid referents. Only when the references themselves go out > of scope will the referents be trashed by the garbage collector. That's true if the variable is defined inside the loop. Each iteration creates a new object, and saving a reference to it keeps it from vanishing. If the variable is defined outside the loop, grabbing a reference inside the loop just gives you multiple references to the same object. (Reminder: I'm talking about Perl, not C.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"