16

Is there any preference/convention/rule on order for defining a variable as static and long/double or other types?

e.g. is

static double a;

same as

double static a;

is it any different for functions? above, a is variable.

jww
  • 97,681
  • 90
  • 411
  • 885
user2178841
  • 849
  • 2
  • 13
  • 26
  • 7
    They mean the same thing. The first version is overwhelmingly more common (in my experience). But ultimately it's just a question of style. – Oliver Charlesworth Jun 25 '13 at 09:06
  • Are the same, but `double static a` gives `warning: ‘static’ is not at beginning of declaration [-Wold-style-declaration]` with `-W` flag on – David Ranieri Jun 25 '13 at 09:09
  • Nope. You just need to have the variable name last. Same with signed/unsigned, you can put them in any order. There was a question here earlier today or yesterday with a great response in it. Here 'tis: http://stackoverflow.com/questions/17287957/is-long-unsigned-as-valid-as-unsigned-long-in-c – enhzflep Jun 25 '13 at 09:09
  • storage class should be first in declaration. – Dayal rai Jun 25 '13 at 09:10
  • 3
    @OliCharlesworth see my answer, it's not only a question of style, the second form is marked as obsolescent. – ouah Jun 25 '13 at 09:15
  • @ouah: Did not know that, so +1 for you! – Oliver Charlesworth Jun 25 '13 at 09:16
  • 3
    The close and downvotes here really aren't warranted. – Jim Balter Jun 25 '13 at 09:19
  • It may be of interest, that some languages do define the preferred order. Example: http://stackoverflow.com/questions/10299067/modifier-keyword-order-in-java – hyde Oct 20 '13 at 19:34

1 Answers1

24

They are equivalent but static at the beginning is preferred.

(C99, 6.11.5p1) "The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature"

ouah
  • 142,963
  • 15
  • 272
  • 331