Re: const and volatile keywords in C

  • From: Tyler Littlefield <tyler@xxxxxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Tue, 20 Jul 2010 10:42:45 -0600

I'm not sure why you would use volatile and const, basically it checks the 
value with volatile rather than reuse the old one from what I remember, which 
is great for threading. Const doesn't lead to speed incrases generally, just 
elimenates you assigning to it, which is helpful.
                Thanks,
Tyler Littlefield
        http://tds-solutions.net
        Twitter: sorressean

On Jul 20, 2010, at 10:38 AM, Øyvind Lode wrote:

> Hi all:
> 
> I know that the "const" keyword declares a value that cannot be change by
> the program and this may lead to better performance.
> If volatile is used the value may be changed by the program, but it may also
> be changed by some outside influence.
> 
> volatile const int index3 = 12;
> volatile int index4;
> 
> The difference between the two as I see it is that the first one use both
> volatile and const and assigns 12 to an integer type to the identifier named
> index3 and the second only uses volatile and declares an integer type
> identified as index4 but does not assign a value.
> 
> So if I do:
> 
> volatile const index3 = 12;
> volatile int index4 = 12;
> 
> Now I have two int types with two identifiers named index3 and index4 with
> the same value of 12.
> What's not clear to me is why only volatile is used and what's the
> difference between using both volatile const to only use volatile?
> 
> 
> __________
> View the list's information and change your settings at 
> //www.freelists.org/list/programmingblind
> 

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: