Mail Archives: djgpp/1997/05/15/20:49:00
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
- Raw text -