static constants

B

Bill Woessner

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
 
D

Deming He

Bill Woessner said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top