const static Vs. static const

Collapse
This topic is closed.
X
X
 
Clear All
new posts
  • Dave

    const static Vs. static const

    const static int ARRAY_SIZE = 4;

    Comeau online gives this warning:
    "ComeauTest .c", line 10: warning: storage class is not first const static
    int ARRAY_SIZE = 4;



    Why is static const preferable to const static?

    Thanks!


  • Ron Natalie

    #2
    Re: const static Vs. static const

    Dave wrote:[color=blue]
    > const static int ARRAY_SIZE = 4;
    >
    > Comeau online gives this warning:
    > "ComeauTest .c", line 10: warning: storage class is not first const static
    > int ARRAY_SIZE = 4;
    >
    >
    >
    > Why is static const preferable to const static?
    >[/color]
    Because it's not legal. The grammar doewsn't allow the
    storage-clas-specifier to be inserted inside the type specifier.
    Comeaus error message is hwoever wrong (or at least misleading.
    The storage class specifier need not be first:

    const int static ARRAY_SIZE = 4;

    is perfectly legal. Inserting static between const and int
    is not however.

    Comment

    • John Carson

      #3
      Re: const static Vs. static const

      "Ron Natalie" <ron@spamcop.ne t> wrote in message
      news:428fd52f$0 $6629$9a6e19ea@ news.newshostin g.com[color=blue]
      > Dave wrote:[color=green]
      >> const static int ARRAY_SIZE = 4;
      >>
      >> Comeau online gives this warning:
      >> "ComeauTest .c", line 10: warning: storage class is not first const
      >> static int ARRAY_SIZE = 4;
      >>
      >>
      >>
      >> Why is static const preferable to const static?
      >>[/color]
      > Because it's not legal. The grammar doewsn't allow the
      > storage-clas-specifier to be inserted inside the type specifier.
      > Comeaus error message is hwoever wrong (or at least misleading.
      > The storage class specifier need not be first:
      >
      > const int static ARRAY_SIZE = 4;
      >
      > is perfectly legal. Inserting static between const and int
      > is not however.[/color]


      Are you sure? Comeau compiles both versions with the same warning. VC++ 7.1
      compiles both versions with no warning.

      --
      John Carson

      Comment

      • Larry I Smith

        #4
        Re: const static Vs. static const

        Ron Natalie wrote:[color=blue]
        > Dave wrote:[color=green]
        >> const static int ARRAY_SIZE = 4;
        >>
        >> Comeau online gives this warning:
        >> "ComeauTest .c", line 10: warning: storage class is not first const static
        >> int ARRAY_SIZE = 4;
        >>
        >>
        >>
        >> Why is static const preferable to const static?
        >>[/color]
        > Because it's not legal. The grammar doewsn't allow the
        > storage-clas-specifier to be inserted inside the type specifier.
        > Comeaus error message is hwoever wrong (or at least misleading.
        > The storage class specifier need not be first:
        >
        > const int static ARRAY_SIZE = 4;
        >
        > is perfectly legal. Inserting static between const and int
        > is not however.[/color]

        GCC g++ v3.3.4 compiles both of these statements without error
        or warning (even with '-Wall -ansi -pedantic' compile options):

        const static int ARRAY_SIZE1 = 4;
        static const int ARRAY_SIZE2 = 4;

        This statement produces the compile error:
        "error: syntax error before `static'"

        const int static ARRAY_SIZE3 = 4;

        Regards,
        Larry

        --
        Anti-spam address, change each 'X' to '.' to reply directly.

        Comment

        • Teddy

          #5
          Re: const static Vs. static const

          const static int ARRAY_SIZE1 = 4;
          static const int ARRAY_SIZE2 = 4;
          const int static ARRAY_SIZE3 = 4;

          VC2005 BETA2 compiles all the three statements without error or warning

          Comment

          • Alf P. Steinbach

            #6
            Re: const static Vs. static const

            * Teddy:[color=blue]
            > const static int ARRAY_SIZE1 = 4;
            > static const int ARRAY_SIZE2 = 4;
            > const int static ARRAY_SIZE3 = 4;
            >
            > VC2005 BETA2 compiles all the three statements without error or warning[/color]

            I'm unable to find any restriction on the order in the standard; assuming
            there is no such there should be six valid combinations.


            --
            A: Because it messes up the order in which people normally read text.
            Q: Why is it such a bad thing?
            A: Top-posting.
            Q: What is the most annoying thing on usenet and in e-mail?

            Comment

            • Teddy

              #7
              Re: const static Vs. static const

              yes, there should be six valid combinations.
              but do they have the same meaning ?
              i think i'm a little bit confused.

              Comment

              • Dave

                #8
                Re: const static Vs. static const


                "Teddy" <duanduan12@hot mail.com> wrote in message
                news:1116731820 .073408.43820@g 49g2000cwa.goog legroups.com...[color=blue]
                > yes, there should be six valid combinations.
                > but do they have the same meaning ?
                > i think i'm a little bit confused.
                >[/color]

                If they're all valid, then yes they would have the same meaning. The
                questions centers around whether or not they are all valid.


                Comment

                • Rolf Magnus

                  #9
                  Re: const static Vs. static const

                  Larry I Smith wrote:
                  [color=blue]
                  > GCC g++ v3.3.4 compiles both of these statements without error
                  > or warning (even with '-Wall -ansi -pedantic' compile options):[/color]

                  You forgot to add -W to the options.
                  [color=blue]
                  > const static int ARRAY_SIZE1 = 4;[/color]

                  With -W, it says:
                  "warning: `static' is not at beginning of declaration"
                  [color=blue]
                  > static const int ARRAY_SIZE2 = 4;
                  >
                  > This statement produces the compile error:
                  > "error: syntax error before `static'"
                  >
                  > const int static ARRAY_SIZE3 = 4;[/color]

                  Comment

                  • Larry I Smith

                    #10
                    Re: const static Vs. static const

                    Rolf Magnus wrote:[color=blue]
                    > Larry I Smith wrote:
                    >[color=green]
                    >>GCC g++ v3.3.4 compiles both of these statements without error
                    >>or warning (even with '-Wall -ansi -pedantic' compile options):[/color]
                    >
                    > You forgot to add -W to the options.
                    >[color=green]
                    >> const static int ARRAY_SIZE1 = 4;[/color]
                    >
                    > With -W, it says:
                    > "warning: `static' is not at beginning of declaration"
                    >[/color]


                    Hmm, you are correct.

                    Thanks for the info about '-W'.

                    The doc supplied with g++ v3.3.4 ('info GCC') does not
                    mention '-W'. It does discuss many '-W...' options
                    that can all be enabled via '-Wall' and disabled with
                    '-w' (lowercase).

                    It seems that '-W -Wall' needs to be specified to
                    turn on all warnings. The '-Wall' switch name is
                    misleading - it doesn't enable 'all' warnings.

                    Sadly, it appears that the GCC docs are incomplete.

                    Regards,
                    Larry

                    --
                    Anti-spam address, change each 'X' to '.' to reply directly.

                    Comment

                    • Ron Natalie

                      #11
                      Re: const static Vs. static const

                      John Carson wrote:
                      [color=blue]
                      > Are you sure? Comeau compiles both versions with the same warning. VC++
                      > 7.1 compiles both versions with no warning.
                      >[/color]

                      No actually, it looks like I was wrong. Comeau's still wrong.
                      The decl-specifier-seq can be made up of an arbitrary order of
                      type-specifiers and storage-class-specifiers. The const (a
                      CV-qualifer) and the int (a simple-type-name) are type-specifiers.
                      Static is a storage-class-specifier. I can't find any applicable
                      semantic restriction that applies.

                      Comment

                      Working...