volatile static int i;
and
static volatile int i;
what is the difference between the two? How does the compiler see this?
volatile static int i;
and
static volatile int i;
what is the difference between the two? How does the compiler see this?
There is no difference, you can specify them in either order.
Both mean the same
Wikepedia gives you information on them http://en.wikipedia.org/wiki/Volatile_variable
The order is irrelevant. static
is a storage duration.
6.2.4 Storage durations of objects
3 An object whose identifier is declared with external or internal linkage, or with the storage-class specifier static has static storage duration. Its lifetime is the entire execution of the program and its stored value is initialized only once, prior to program startup.
and:
6.7.3 Type qualifiers
An object that has volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects. Therefore any expression referring to such an object shall be evaluated strictly according to the rules of the abstract machine, as described in 5.1.2.3. Furthermore, at every sequence point the value last stored in the object shall agree with that prescribed by the abstract machine, except as modified by the unknown factors mentioned previously.114) What constitutes an access to an object that has volatile-qualified type is implementation-defined.
In your example the order doesn't matter but the following is also valid
static int volatile i;
which shows that the order in general is relevant, since you can't put static
after int
. static
qualifies the variable, volatile
and const
qualify the type.