From: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire) Newsgroups: comp.os.msdos.djgpp Subject: Re: Any tips on optimizing C code? Date: 15 May 1997 22:45:04 GMT Organization: The National Capital FreeNet Message-ID: <5lg3lg$iiu@freenet-news.carleton.ca> References: <33775c59 DOT 19219875 AT news DOT cis DOT yale DOT edu> <01bc5f6f$c3000be0$cf1afec3 AT robert> <337865D0 DOT FB8 AT cornell DOT edu> <33793055 DOT 19327180 AT news DOT cis DOT yale DOT edu> <5lfsrj$sh7 AT dfw-ixnews3 DOT ix DOT netcom DOT com> Reply-To: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire) NNTP-Posting-Host: freenet2.carleton.ca Lines: 27 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk William H. Ivey (wivey AT ix DOT netcom DOT com) writes: > re: Global/static ints: > I've found them to be slower in some cases. One thing to watch out for > is the "reluctance" of many compilers to optimize these things - you > often have to tell it it's OK by way of a command line switch or > #pragma. (The reason is that the safe assumption for the compiler is > that these values may not be stable - that is, they might be changed by > something outside of the function while the function is processing > them.) BTW, try putting commonly used constants into stack variables > rather than putting them into inner loops; sometimes helps a lot. Actually a *good* compiler optimizer will not be leery of touching static and global variables, unless they are declared "volatile", because a *good* programmer sticks "volatile" on any such variable that gets altered by interrupts, such as timers or whatnot. I think the rule is, if it's not volatile it's fair game for optimizing, and if it should have been volatile, the programmer is fair game for debugging a mystery error for the next thirty hours. :) -- .*. Where feelings are concerned, answers are rarely simple [GeneDeWeese] -() < When I go to the theater, I always go straight to the "bag and mix" `*' bulk candy section...because variety is the spice of life... [me] Paul Derbyshire ao950 AT freenet DOT carleton DOT ca, http://chat.carleton.ca/~pderbysh