Mail Archives: djgpp/1996/06/16/15:07:43
Andrew M. Langmead <aml AT world DOT std DOT com> wrote:
> Lennart Steinke <steinke AT zeus DOT adv-boeblingen DOT de> writes:
> >
> >int b;
> >
> >b=g;
> >while (b==g);
> >
> >this loop is always optimized to
> >while(1);
>
> Why don't you declare the variable g as a volatile int?
That'd be my recommentation, too. If, for some reason, you only want
it unoptimized that one place, try this macro:
#define VOL(var) (*((volatile typeof(f)*)&f))
It basically re-types the variable as volatile, assuming it can be
re-typed. Don't try this on a local or register variable. So you'd write:
" while (b == VOL(g)); ". That forces gcc to load the value from g, but
only in that one loop.
-Dan Nelson
dnelson AT emsphone DOT com
- Raw text -