Keil Logo

C166: PURPOSE OF 'VOLATILE' AND 'CONST' KEYWORDS


Information in this article applies to:

  • C166 Version 3.12
  • C166 Version 4.02

QUESTION

Do the 'const' or 'volatile' keywords have any particular meaning to the C166 3.12 or 4.x compilers?

ANSWER

Declaring a variable as const is identical to declaring the variable without 'const', the only difference is that the compiler will warn you if you try to modify a const.

Consts are placed in the NCONST/FCONST/HCONST class depending on if they are near, far or huge respectively.

Declaring a variable as volatile ensures that it is not affected by the optimizer. For example, if you locate a variable called 'rtc' at the address for some memory-mapped hardware and you only ever write to that location, then the optimizer sees that you never do anything with the variable once initialized. It will be optimized out. Declaring the variable as volatile avoids that problem.

Last Reviewed: Wednesday, June 9, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.