www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/16/15:07:43

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: <Pine DOT VUL DOT 3 DOT 91 DOT 960613123358 DOT 3422E-100000 AT zeus DOT adv-boeblingen DOT de> <Dszo6x DOT D9M AT world DOT std DOT com>
NNTP-Posting-Host: 199.67.51.101
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


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