delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2006/03/29/05:15:50

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Martin Steuer <martin AT x DOT invalid>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: new gcc 4.10 behaviour
Date: Wed, 29 Mar 2006 12:08:03 +0200
Lines: 51
Message-ID: <48v4k4Fm65abU1@news.dfncis.de>
References: <1143542847 DOT 613686 DOT 87820 AT v46g2000cwv DOT googlegroups DOT com> <48sjvaFlir4cU1 AT news DOT dfncis DOT de>
Mime-Version: 1.0
X-Trace: news.dfncis.de mvTZmDU9FAsW/Bx2LVLIBwyvPMqJRM4d8yPqPkYXbYS83u9/l0e00pY//h
User-Agent: Mozilla Thunderbird 1.0 (X11/20041206)
X-Accept-Language: en-us, en
In-Reply-To: <48sjvaFlir4cU1@news.dfncis.de>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019