Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the order of static and volatile keywords matter?

Tags:

c

volatile static int i; 

and

static volatile int i;  

what is the difference between the two? How does the compiler see this?

like image 268
Manoj Avatar asked Aug 18 '10 05:08

Manoj


2 Answers

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.

like image 160
dirkgently Avatar answered Nov 02 '22 23:11

dirkgently


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

like image 29
Dean Harding Avatar answered Nov 03 '22 01:11

Dean Harding