ARM Technical Support Knowledge Articles

PURPOSE OF 'VOLATILE' AND 'CONST' KEYWORDS

Applies to: C166 C Compiler

Answer


Information in this article applies to:


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.

Article last edited on: 2004-06-09 15:25:14

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential