By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 954 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

static constants

P: n/a
Is there any benefit to be gained from declaring a local constant static?
The only scenario I can envision is if the constant were a large,
complicated object or perhaps a large array. Making it static would
ensure it's only allocated once. The flip side, of course, is that it
hangs around until your program terminates.

Sorry if this is an old topic. I've thought about it for a while and
haven't come to any resolution. Thanks.

--Bill

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Bill Woessner <wo******@cs.umd.edu> wrote in message
news:Pi**************************************@utz. cs.umd.edu...
Is there any benefit to be gained from declaring a local constant static?
The only scenario I can envision is if the constant were a large,
complicated object or perhaps a large array. Making it static would
ensure it's only allocated once. The flip side, of course, is that it
hangs around until your program terminates.

Sorry if this is an old topic. I've thought about it for a while and
haven't come to any resolution. Thanks.

--Bill

"const" makes it not to be changed.
"static" limits access to the variable only from within the local scope.
"static" will initialize at the first time entering the scope and skip the
line of code after that - this do save a little bit of execution time though
not much.
Jul 22 '05 #2

P: n/a
Deming He wrote:
Bill Woessner <wo******@cs.umd.edu> wrote in message
news:Pi**************************************@utz. cs.umd.edu...
Is there any benefit to be gained from declaring a local constant static?

[...] "static" limits access to the variable only from within the local scope.

[...]

No it doesn't.

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.