const and volatile keywords in C

  • From: Øyvind Lode <oyvind.lode@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 20 Jul 2010 18:38:22 +0200

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

Other related posts: