Posts

Showing posts from May, 2011

Article to interpret const and volatile

Use of 'const' and 'volatile' Applies to: Software Development Toolkit (SDT) Description The correct placement of the type qualifiers ' const ' and ' volatile ' can sometimes be confusing, especially when applied to a pointer or the thing it points to. Solution Here is a simple rule which may help: place ' const ' (or ' volatile ') *after* the thing you're saying is constant (or volatile). to declare a constant integer, use ' int const xxx ', instead of ' const int xxx '. to declare a pointer to a constant integer, put ' const ' after ' int ' to get ' int const *ptr '. to declare a constant pointer to an integer, put ' const ' after ' * ' and get ' int * const ptr '. to declare a constant pointer to a constant integer, use ' int const * const ptr '. to declare a constant pointer to a volatile integer, use ' int volatile * const ptr '.