Results 1 to 3 of 3
Dear All,
Please can any one provide some information on real-time applications of CONST and VOLATILE CONSTANT qualifers.
Regards,
Sri Anu....
- 05-25-2009 #1Just Joined!
- Join Date
- May 2009
- Posts
- 11
C Qualifiers
Dear All,
Please can any one provide some information on real-time applications of CONST and VOLATILE CONSTANT qualifers.
Regards,
Sri Anu.
- 05-25-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
In general, const means that the variable is a constant - you cannot modify it. A volatile constant means that the variable can change between reads, but only by an external force (the kernel, for example). An example of a volatile constant could be something like the CPU temperature. The kernel monitors that, and if you had an external reference to that variable, it could change, even while you read it. But YOU could not change it in your code.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 05-27-2009 #3
On a lower level, "volatile" tells the compiler not to store the variable in a register. This is because, as Rubberman said, it can change due to factors outside of your own code.
As for "const", on its simplest, it is as Rubberman says: you cannot modify the variable. However, it gets a bit more difficult when pointers get involved:
I hope that helps.Code:int *number; # normal int * const number; # The value stored at number (*number) can change, but number itself may not int const *number; # The value stored at number (*number) may not change, but number may int const * const number; # number can neither be reassigned nor have the value it points to be changed
DISTRO=Arch
Registered Linux User #388732


Reply With Quote