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?
const int static ARRAY_SIZE = 4;
is perfectly legal. Inserting static between const and int
is not however.
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;
Anti-spam address, change each 'X' to '.' to reply directly.
VC2005 BETA2 compiles all the three statements without error or warning
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?
Q: What is the most annoying thing on usenet and in e-mail?
If they're all valid, then yes they would have the same meaning. The
questions centers around whether or not they are all valid.
> GCC g++ v3.3.4 compiles both of these statements without error
> or warning (even with '-Wall -ansi -pedantic' compile options):
You forgot to add -W to the options.
> const static int ARRAY_SIZE1 = 4;
With -W, it says:
"warning: `static' is not at beginning of declaration"
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
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.
> Are you sure? Comeau compiles both versions with the same warning. VC++
> 7.1 compiles both versions with no warning.
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.