www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/15/11:15:31

From: Nate Eldredge <neldredge AT hmc DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: THE -O2 PROBLEM - PART II
Date: 15 Apr 2000 01:54:34 -0700
Organization: InterWorld Communications
Lines: 32
Message-ID: <83og7b3fsl.fsf@mercury.st.hmc.edu>
References: <38F20E7A DOT 3330E9A4 AT mtu-net DOT ru> <38F6C64E DOT C7753C6C AT mtu-net DOT ru> <8d7l3g$j3i$1 AT nets3 DOT rz DOT RWTH-Aachen DOT DE> <38F76B94 DOT 5E968BA7 AT mtu-net DOT ru> <38F7A6FE DOT ED9B3E59 AT mtu-net DOT ru> <38F82ABA DOT FEBEB2B0 AT is DOT elta DOT co DOT il> <38F82569 DOT 817316A6 AT mtu-net DOT ru>
NNTP-Posting-Host: mercury.st.hmc.edu
Mime-Version: 1.0
X-Trace: nntp1.interworld.net 955789134 74076 134.173.45.219 (15 Apr 2000 08:58:54 GMT)
X-Complaints-To: usenet AT nntp1 DOT interworld DOT net
NNTP-Posting-Date: 15 Apr 2000 08:58:54 GMT
User-Agent: Gnus/5.0802 (Gnus v5.8.2) Emacs/20.5
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Alexei A. Frounze" <alex DOT fru AT mtu-net DOT ru> writes:

> it eliminates C code but not inline asembly.
> 
> For example:
> 
> if (KeyMap[sTab]) {		// key is pressed
>   do_something();
>   while (KeyMap[sTab]) {};	// this line is replaced with infinite loop
> }
> 
> But I need that line AS-IS.

A C compiler assumes that code is only called by "normal" methods.
Hence, it sees the loop, realizes there is no way for KeyMap[sTab] to
change, and deletes the unnecessary test.  This is legal.

However, you are breaking this rule: I presume that flag is set by an
interrupt handler or some such beast, which is not called by normal
program flow methods.  The compiler doesn't expect this.  However, you
can tell it to expect it.  Declare KeyMap as volatile:

volatile char KeyMap[]; /* or whatever */

The compiler will then ensure that every access to KeyMap is done as
written.  This of course prevents many optimizations, in general, but
here is necessary.

-- 

Nate Eldredge
neldredge AT hmc DOT edu

- Raw text -


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