interchanging int and static

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • destination
    New Member
    • Dec 2009
    • 34

    interchanging int and static

    static int i;
    int static i;

    Can i interchange static and int while defining a variable.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What does your compiler say about this? Did it complain?

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Not to mention why would you want to?

      Comment

      • destination
        New Member
        • Dec 2009
        • 34

        #4
        The compiler didnot complain.
        I just asked it to know if this is possible there is no other reason for that.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Then it's OK.

          Some programmers prefer:

          Code:
          int static i;
          because parsing right to left you read "i is a static int".

          Others prefer:

          Code:
          static int i;
          because they read right to left: " i is an int that is static".

          It comes down to emphasizing the fact that i is static or that i is an int.

          You will find this also works for const:

          Code:
          const int i = 0;
          int const i = 0;

          Also, in C (but not C++) you can even omit the int because int is the default type in C. Default-int is not supported in C++.

          Comment

          • donbock
            Recognized Expert Top Contributor
            • Mar 2008
            • 2427

            #6
            Default-int is explicitly deprecated in the C99 Standard. This is considered fair warning by the Standards people that the feature might well be deleted from the next version of the Standard.

            On the other hand, it is common for compilers to have some mechanism (perhaps a command line argument) to make the compiler compliant with earlier versions of the Standard in order to support legacy code.

            Comment

            Working...