Mail Archives: djgpp/2006/04/06/16:01:21
Brian Inglis <Brian DOT Inglis AT systematicsw DOT invalid> wrote:
> That kind of optimization is forbidden unless the (external) function
> is declared with attributes pure or const (clock is not), or the
> compiler can sufficiently determine the effect of the (internal)
> function:
The latter is the case. The Ack() function in the example is
completely self-contained, changes no static variables or has any
other effect that any other function could possibly depend on ---
except if that other function depends on volatile variables, which
clock() happens to do. I.e. Ack() is a "pure" function, in terms of
GCC attributes. For all the C standard is concerned, Ack() could be
precomputed at compile time and implemented as a lookup table for all
arguments below some threshold.
OTOH, clock() isn't exactly deterministic to begin with, so there's no
new indetermination added by this optimization --- it's just a
gradual, not a qualitative change.
> even declaring the internal function static did not change the code.
That's because the compiler has determined already by itself that this
call of the function can be treated as if it had internal linkage
(i.e. as if it were declared static), and partially inlined it.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -