Mail Archives: djgpp/2006/03/29/05:15:50
Hans-Bernhard Broeker wrote:
> I.e. there's nothing in the language definition forbidding the compiler
> to change
>
>
>> clock_t t0=clock();
>> int ackret=Ack(3, n);
>> clock_t t1=clock();
>
>
>> printf("Ack(3,%d): %d\n", n, ackret);
>> printf("Time: %g secs\n", 1.0*(t1-t0)/CLOCKS_PER_SEC);
>
>
> into
>
>
>> clock_t t0=clock();
>> clock_t t1=clock();
>> int ackret=Ack(3, n);
>
>
>> printf("Ack(3,%d): %d\n", n, ackret);
>> printf("Time: %g secs\n", 1.0*(t1-t0)/CLOCKS_PER_SEC);
>
>
> or even
>
>
>> int ackret=Ack(3, n);
>> printf("Ack(3,%d): %d\n", n, ackret);
>> clock_t t0=clock();
>> clock_t t1=clock();
>> printf("Time: %g secs\n", 1.0*(t1-t0)/CLOCKS_PER_SEC);
>
>
I'm curios, would it also be possible, that the optimizer reorders the
calls to clock to:
clock_t t1 = clock();
clock_t t0 = clock();
And if not, why? Would the optimizer have to assume that the first call
to clock has changed the internal state of that function?
And in general: how can one guarantee a certain order of execution for
code like that from the OP? He suggested that using static or global
variables seems to be a solution, but is this really the way to do it?
Martin
- Raw text -