what is the difference with
unsigned const volatile data;
and
unsigned volatile data;
Printable View
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;
}
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.