what is the difference with
unsigned const volatile data;
and
unsigned volatile data;
what is the difference with
unsigned const volatile data;
and
unsigned volatile data;
You can't change the value of 'data', but volatile indicates that something else may change its value.Code:unsigned const volatile data;
You can change the value of 'data', and volatile indicates that something else may change its value too.Code:unsigned volatile data;Code:#include <stdio.h> int main(void) { unsigned const volatile a = 1; /* initialization, ok */ unsigned volatile b = 1; /* initialization, ok */ a = 4; /* assignment, error - 'cannot modify a const object' */ b = 5; /* assignment, ok */ while(a && b) { printf("a = %u, b = %u\n", a, b); } return 0; }
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
A lot of uses of "volatile" are with systems that interface directly to hardware, where they're talking to something other than RAM, like a device control register. So, to answer your question, the difference between the 2 is that the "const" means you're accessing a read-only memory address.