Newsgroups: comp.os.msdos.djgpp From: Peter Berdeklis Subject: Re: Volatile Message-ID: Nntp-Posting-Host: chinook.physics.utoronto.ca Sender: news AT info DOT physics DOT utoronto DOT ca (System Administrator) Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Organization: University of Toronto - Dept. of Physics In-Reply-To: <33E8495B.3EBC@starnets.ro> Date: Thu, 7 Aug 1997 17:12:12 GMT References: <33E8495B DOT 3EBC AT starnets DOT ro> Lines: 29 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On Wed, 6 Aug 1997, Korenschi Francisc Eduard wrote: > Hi, > > > I know it sounds crazy, but what does the 'voltaile' with a > variable/function ? > > > Thanx for bothering, > Eduard The 'volatile' keyword is a message to the compiler that it can't make any assumptions about the value of variable when optimizing the code. This is usually because the variable might be changed by an interrupt handler or hardware, or something else that the compiler could never know about. Therefore, everytime you use the variable in your code the compiler explicitly loads it from memory, instead of assuming that the value is stored in a register becuase it used it in your last line of code. 'volatile' means nothing to a function, and you should probably be getting a warning if you compile with -Wall. It can be useful with asm statements in C/C++ code, because it tells the compiler not to move the code when it optimizes, which it is otherwise free to do. --------------- Peter Berdeklis Dept. of Physics, Univ. of Toronto