Mail Archives: djgpp/2006/04/01/10:47:57
> > And if not, why? Would the optimizer have to assume that the first call
> > to clock has changed the internal state of that function?
>
> Generally it would --- but not if the two calles are initializers of
> variables.
>
> > And in general: how can one guarantee a certain order of execution for
> > code like that from the OP?
>
> By making them statements, rather than series of variable definitions.
> That changes introduces what the C standard calls "sequence points",
> which the optimizer must respect, and thus maintains order of things.
This only makes my confusion worse. According to
http://en.wikipedia.org/wiki/Sequence_point
initializers constitute sequence points ("9. At the end of an
initializer."). So in the case
int a = clock();
// ...
int b = clock();
the compiler should (IMHO) never be allowed to reorder these two. Or
am I missing something? Or is Wikipedia wrong, *again*? :)
Egon
- Raw text -