Xref: news2.mv.net comp.os.msdos.djgpp:5043 From: dan AT dan DOT emsphone DOT com (Dan Nelson) Newsgroups: comp.os.msdos.djgpp Subject: Re: How to tell djgpp NOT to optimate a line of code Date: 14 Jun 1996 21:23:31 GMT Organization: Executive Marketing Services, Inc. Lines: 25 Message-ID: <4psl8j$3va@client3.news.psi.net> References: NNTP-Posting-Host: 199.67.51.101 Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Andrew M. Langmead wrote: > Lennart Steinke 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