X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: Martin Steuer 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 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 Precedence: bulk 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