delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/11/01:33:53

Newsgroups: comp.os.msdos.djgpp
From: Peter Berdeklis <peter AT atmosp DOT physics DOT utoronto DOT ca>
Subject: Re: Volatile
Message-ID: <Pine.SGI.3.91.970807130631.13615A-100000@atmosp.physics.utoronto.ca>
Nntp-Posting-Host: chinook.physics.utoronto.ca
Sender: news AT info DOT physics DOT utoronto DOT ca (System Administrator)
Mime-Version: 1.0
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

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

- Raw text -


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