www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/02/05/09:14:00

To: apr AT xs4all DOT nl (Ane Roos)
Cc: djgpp-list AT sun DOT soe DOT clarkson DOT edu
Subject: Re: Undesired optimization.
Date: Sun, 05 Feb 95 16:05:03 +0200
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>

> void wait(void) {               
>     int nu,straks;
>     nu=_farpeekw(_go32_conventional_mem_selector(),MK_FP(0x40,0x6c)); 
>     straks=nu;
>     while (nu==straks){
>     straks=_farpeekw(_go32_conventional_mem_selector(),MK_FP(0x40,0x6c)); 
>     continue;    
>     }
> }
>
> 	This doesn't work,however,because the compiler(optimization on)
> doesn't honor the second _farpeekw but simply uses the stored result
> of the first one.Optimization is desirable because of the farpeek

Your code is essentially correct.  Your problem has nothing to do
with DOSsisms.  If you have a variable whose value could change
behind the scenes, and you don't want the compiler to optimise
that variable out of your loop, you should declare it ``volatile'':

	volatile int straks;

That's it.

>   Being fairly new on the Net,I'm reading tons of FAQ-like material.
> I find the DJGPP-one outstanding,both for its contents and for its
> beautifully crisp,good-natured and unperturbed style.The tip to
> stubedit GCC did wonders for performance on my 4Mb 386SX.Thank you,
> Eli Zaretski.

Thank you for your kind words.  It's good to know somebody not only
reads what I've written, but also finds the info helpful.  (And btw,
that double ``ii'' at the end of my name isn't a bug, it's a feature.
No offence taken.)

FYI, there are better ways to wait than what you use.  One is to use
the sleep() or usleep() functions (look them up in the libc.a docs)
which have an advantage of being portable to other platforms (e.g.,
Unix).  The other is to use the delay() function which has a
1-millisecond resolution (your method has only a 54-millisecond
resolution) and is available with most DOS-based C compilers.

- Raw text -


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