Difference between revisions of "Const and volatile type qualifiers"
From Teknologisk videncenter
m |
m (→Links) |
||
Line 1: | Line 1: | ||
+ | =const= | ||
+ | ''const'' means that something is not modifiable, so a data object that is declared with const as a part of its type specification must not be assigned to in any way during the run of a program. | ||
+ | =volatile= | ||
+ | The use of ''volatile'' ensures that the compiler always carries out the memory accesses, rather than optimizing them out (for example if the access is in a loop). | ||
+ | |||
+ | =Memorymapped access to a register= | ||
+ | ==Example 1== | ||
+ | In the example below the register 32 bit register located at address 0x40000 can be accessed | ||
=Links= | =Links= | ||
− | [http://publications.gbdirect.co.uk/c_book/chapter8/const_and_volatile.html Const and volatile] | + | *[http://publications.gbdirect.co.uk/c_book/chapter8/const_and_volatile.html Const and volatile] |
*[http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3750.html armcc/tcc: Placing C variables at specific addresses - memory-mapped peripherals] | *[http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3750.html armcc/tcc: Placing C variables at specific addresses - memory-mapped peripherals] | ||
[[Category:C]][[Category:C++]] | [[Category:C]][[Category:C++]] | ||
+ | *[http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3736.html Use of 'const' and 'volatile'] |
Revision as of 10:04, 31 August 2011
const
const means that something is not modifiable, so a data object that is declared with const as a part of its type specification must not be assigned to in any way during the run of a program.
volatile
The use of volatile ensures that the compiler always carries out the memory accesses, rather than optimizing them out (for example if the access is in a loop).
Memorymapped access to a register
Example 1
In the example below the register 32 bit register located at address 0x40000 can be accessed