Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!nx02.iad01.newshosting.com!newshosting.com!216.196.98.142.MISMATCH!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 14 Feb 2012 23:53:01 -0600 Message-ID: <4F3B483F.7D75@mindspring.com> Date: Wed, 15 Feb 2012 00:53:03 -0500 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: global/static variables & loops References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 34 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.216.252 X-Trace: sv3-9FxcdRZuwQWrS9Dv/9DlyfqNg2l3HUG0IbIAr6IIezpNOFuk2zxFdRpZWnbKtgBdjse4rOGRSey5WRG!lBbWo1Zc2l+n2dDOI5ImCnBK5NPmfVCTrM2wgt+i8HxNaYUeV6NgiOY2z+a4bDLG9VqEnubtFbUE!S7jiLNqwjHI= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2304 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:17355 Eric Sosman wrote: > > On 2/14/2012 2:56 PM, Rob Janecek wrote: > > Hello, > > In some coding advice I saw on the internet, we are urged to "avoid > > referring to global or static variables inside the tightest loops". > > Reasonable advice. I'd go a little further, and delete the > final four words. Global variables have a way of tying together > pieces of your program that you didn't realize were related, and > this effect increases as the program grows larger. It's no good > having modular code if you also have spaghetti data. > > That said, I'd also point out that "avoid" is not absolute; > perhaps "prefer not" would capture the notion more aptly. For > example, it's hard to argue against the global variable in > > printf ("Hello, world!\n"); > > (If you don't see the global variable, try using fprintf() instead.) > That's a sort of yardstick you might want to use: When you're thinking > of making some variable global, as yourself whether it's as "useful" > to the program at large as `stdout' is. On my machine, stdout is an address constant, which is not something that I would refer to as a "variable". I can compile this: FILE *array[] = {stdout}; -- pete