Q's of: static, variable, and return functions
#4

Global static variables:
Assume you have
pawn Код:
static MyStaticVar = 4; // in the file MyInclude1.inc
// and the variable
new MyGlobalVar = 5;
Now you include MyInclude in your gamemode.
The difference is now that you can use MyGlobalVar in your gamemode but you can't use MyStaticVar because it can only be used in the file where it's declared.

---

Local static variables are like global variables BUT the can only be used in the function where the get declared.
Local static variables do NOT get deleted/reset after the function has been performed.

Example:
pawn Код:
MyFunc1 ()
{
    static var1 = 0;
    var1++;
    printf ("var1 = %d", var1); // Will print 1, 2, 3, 4 => Will increase by 1 everytime the function gets called.
}

MyFunc2 ()
{
    new var2 = 0;
    var2++;
    printf ("var2 = %d", var2); // Will ALWAYS print 1
}
Reply


Messages In This Thread
Q's of: static, variable, and return functions - by ||123|| - 22.07.2011, 10:25
Re: Q's of: static, variable, and return functions - by MadeMan - 22.07.2011, 10:45
Re: Q's of: static, variable, and return functions - by ||123|| - 22.07.2011, 11:35
Re: Q's of: static, variable, and return functions - by Double-O-Seven - 22.07.2011, 11:42
Re: Q's of: static, variable, and return functions - by Grim_ - 22.07.2011, 11:46
Re: Q's of: static, variable, and return functions - by MadeMan - 22.07.2011, 11:53
Re: Q's of: static, variable, and return functions - by ||123|| - 22.07.2011, 12:01
Re: Q's of: static, variable, and return functions - by Roko_foko - 22.07.2011, 12:16

Forum Jump:


Users browsing this thread: 1 Guest(s)