473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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!
Jul 23 '05 #1
10 21195
Dave wrote:
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?

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.
Jul 23 '05 #2
"Ron Natalie" <ro*@spamcop.net> wrote in message
news:42**********************@news.newshosting.com
Dave wrote:
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?

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.

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

--
John Carson

Jul 23 '05 #3
Ron Natalie wrote:
Dave wrote:
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?

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.


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.
Jul 23 '05 #4
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

Jul 23 '05 #5
* Teddy:
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


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?
Jul 23 '05 #6
yes, there should be six valid combinations.
but do they have the same meaning ?
i think i'm a little bit confused.

Jul 23 '05 #7

"Teddy" <du********@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
yes, there should be six valid combinations.
but do they have the same meaning ?
i think i'm a little bit confused.


If they're all valid, then yes they would have the same meaning. The
questions centers around whether or not they are all valid.
Jul 23 '05 #8
Larry I Smith wrote:
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"
static const int ARRAY_SIZE2 = 4;

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

const int static ARRAY_SIZE3 = 4;


Jul 23 '05 #9
Rolf Magnus wrote:
Larry I Smith wrote:
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
'-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.
Jul 23 '05 #10
John Carson wrote:
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.
Jul 23 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kavitha | last post by:
Hi Pals, I am confused between const and static readonly in C#. I want to know the difference between then. Please give me clear explanation. thanks in advance. -- Kavitha
1
by: Santa | last post by:
Exact difference between 'const char *' and 'char *', also diff between 'const' and 'static', also at what conditions it can be used?. Thanks.
19
by: cody | last post by:
Iam wondering what the benefit of using const over static readonly is. static readonly is a runtime constant and can be set once in the initializer or the static ctor, whereas const is suffering...
4
by: Ant | last post by:
Hi, I'm having trouble trying to define the difference between declaring a field in a class const or static. i've noted that when referencing them from the class that a const is symbolized with...
3
by: shaun | last post by:
I should like to use a map as a look-up table from one string to another. I know the look up I want to use at compile time, and I dont want to spend time during running to construct the object with...
5
by: Sek | last post by:
hi folks, i have a bunch of strings used in my code in many places. these strings reside inside a instantiable class. so, i want to replace these with constant/static variable to control the...
5
by: John Goche | last post by:
Hello, I would like to know whethere there is a difference between a const variable and a static const variable inside a class. After all, if a variable is const in a class, the compiler can...
3
by: er | last post by:
hi all, probably a simple question: i'm used to static const T, i can also understand static const T* const, but i'm not sure what this, for example, means: template <class T> struct...
7
by: JPS | last post by:
Can someone please refresh my memory here, but what is the difference between a Static variable (or method) and a Const?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.