12.08.2014, 10:29
what make static and new different? can you explain it to me?
Sorry for my bad english
Sorry for my bad english
for (new i = 0; i < 3; i++) { new j = 1; printf("%d", j); j++; }
1 1 1
for (new i = 0; i < 3; i++) { static j = 1; printf("%d", j); j++; }
1 2 3
Originally Posted by pawn-lang
When a local variable is declared with the keyword static
rather than new, the variable remains in existence after the end of a function. This means that static local variables provide private, permanent storage that is accessible only from a singl e function (or compound block). Like global variables, static local varia bles can only be initialized with constant expressions. |
myfunction()
{
static x=5;
}
#include <a_samp>
main(){}
public OnFilterScriptInit()
{
printf("static abc: %d",ReadAmxMemory(myfunc()));
return 1;
}
myfunc()
{
static abc=200;
return ref(abc);
}
ref(...)
{
assert(numargs() == 1);
#emit load.s.pri 12 // first argument
#emit retn
return 0; // make compiler happy
}
ReadAmxMemory(address)
{
#emit lref.s.pri address
#emit retn
return 0; // make compiler happy
}