Jump to content
  • Advertisement
Sign in to follow this  
Goku17c

static const , const static

This topic is 4389 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone. I am new to these forums. I have been programming for about 2 years allready though. Nice to meet you all. Anyways, I was wonderign if anyone here could answer this for me... what is the differance between declaring objects (or methods w/e) like so... static const ... or const static ... Both in global and local scope would be cool if they are differant. And yes I allready know about declaring static const members in a class to make derived objects only create 1 copy of it. But I know there is a real differance, I am unsure though. I was thinking it has something to do with the scope or linkage perhaps, but again I am not sure. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Nothing. These are all the same:
    static const int ...
static int const ...
const static int ...
const int static ...
int const static ...
int static const ...

Share this post


Link to post
Share on other sites
I don't think that is allways true, I was told by a programmer in a commercial game developement company thier was a differance.

He told me to figure it out =/. It could be something to do with classes, and member functions, or just member objects.

I don't see a diferance either. idk...

Here is what I was givin.



const static int testCheck = 0;

and how that differs from

static const int testCheck = 0;




Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Goku17c
I don't think that is allways true, I was told by a programmer in a commercial game developement company thier was a differance.

He told me to figure it out =/. It could be something to do with classes, and member functions, or just member objects.

I don't see a diferance either. idk...

Here is what I was givin.



const static int testCheck = 0;

and how that differs from

static const int testCheck = 0;


Just because someone is a programmer in a commercial game company doesn't make then smart. The two statements are equivilent. But then again, I work in a commercial game company, so take my word with a grain of salt.

Share this post


Link to post
Share on other sites
The order shouldn't matter. Possibly unless you have a pointer, then the position of const might make a difference.

static const int * foo; // non-constant pointer to a constant variable.
static int * const foo; // constant pointer to a non-constant variable.

Share this post


Link to post
Share on other sites
Just a cute little something relevant to the thread:

http://www.research.att.com/~bs/bs_faq2.html#constplacement

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:

Just because someone is a programmer in a commercial game company doesn't make then smart. The two statements are equivilent. But then again, I work in a commercial game company, so take my word with a grain of salt.


HA! Ain't that the truth?

Share this post


Link to post
Share on other sites
Yea none of that is what I am looking for. Not a const correctness thing. or the position of const. I guess I was wrong in my question actually.

I think it may be a differance in the way the compiler addresses them.
Even if they have the same end result, They may be applied differant from the compiler and have a differant cost, even if a small one.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!