Is there any use of declaring a global variable as static? If it it then how???
Is there any use of declaring a global variable as static? If it it then how???
sure there is, say you have a program that needs to use pi, or any number, very accuretly several times in your program...well no ones gonna change pi, and no one wants to type out
3.141592653589793238462643383279502884197169399375 10582097494459....
a bunch of times, so just do it once.
I don't think so. Perhaps when linking several modules together, but that's what extern is for...
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Aren't you thinking of const now...?Originally posted by kermi3
sure there is, say you have a program that needs to use pi, or any number, very accuretly several times in your program...well no ones gonna change pi, and no one wants to type out
3.141592653589793238462643383279502884197169399375 10582097494459....
a bunch of times, so just do it once.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
global, static means global but for that module only
in a function, static means global but for that function only
in a class, static means global but for that class only.
so....
in your example, static globals basically are not available outside that module and you can have the same name be reused in another module and represent another variable
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
global static is deprecated.
should beCode:static int a = 23;
Code:namespace { int a = 23; }
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling