Does static and volatile keywords make sense?

volatile static int i; 

and

 static volatile int i; 

What is the difference between the two? How does the compiler see it?

+5
source share
4 answers

Order doesn't matter. static - storage time.

6.2.4 Duration of storage of objects

3 An object whose identifier is declared with external or internal communication or with the static static storage class has a static storage duration. Its service life is the entire execution of the program and its stored value is initialized only once, before the program starts.

and

6.7.3 Typical classifiers

An object that has a mutable type can be modified in ways that are unknown to the implementation or have other unknown side effects. Therefore, any expression that refers to such an object is evaluated strictly in accordance with the rules of an abstract machine, as described in 5.1.2.3. In addition, at each point in the sequence, the last value stored in the object agrees with what is prescribed by the abstract machine, unless otherwise unknown factors mentioned previously .114). What constitutes access to an object that is of an unstable type is determined by the implementation.

+3
source

There is no difference, you can specify them in any order.

+2
source

Both mean the same

Wikepedia gives you information about them http://en.wikipedia.org/wiki/Volatile_variable

+1
source

In your example, the order does not matter, but the following is also true:

 static int volatile i; 

which shows that order generally matters, since you cannot put static after an int . static corresponds to a variable, volatile and const corresponds to a type.

+1
source

All Articles