1

In C, is there a difference between static const and const static in variable declaration?

const static gives warning: 'static' is not at beginning of declaration.

Its not my code and all the other questions I saw were about C++ and static has different meaning there.

jww
  • 97,681
  • 90
  • 411
  • 885
  • I am not so sure this is a duplicate. This question asks about the order of *storage-class specifiers* and *type-qualifiers*. [That question](https://stackoverflow.com/questions/17293232/order-of-defining-types) asks about the order of *storage-class specifiers* and *type-specifiers*. They are different, and the standard’s statements about them are different. Note that 6.7.3 says the order of type qualifiers does not matter, but 6.7.2 merely says any order may be used; it does not say the order does not matter. That is possibly an oversight, but it is a difference that should be addressed. – Eric Postpischil Mar 08 '18 at 12:43
  • You should show the exact declaration that is causing the warning. Also see [Order of defining types](https://stackoverflow.com/q/17293232/608639) – jww Mar 08 '18 at 14:56

1 Answers1

3

The order of qualifiers and specifiers does not matter. Per C 2011 [N1570] 6.7.3 10:

… the order of type qualifiers within a list of specifiers or qualifiers does not affect the specified type.

and 6.7.2 2:

… the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.

However, the standard describes using storage-class specifiers after other specifiers or qualifiers as obsolescent, in 6.11.5:

The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature.

“Obsolescent” means the feature may be considered for withdrawal in future revisions of the standard (per Introduction paragraph 2). Thus, compilers that issue a warning for using const static are suggesting a change that helps prepare the source code for a future version of C.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312