static variable in function
does Ziron support static variable inside the function or procedure ?
http://www.freewebs.com/ogremagic/index.htm
A community discussion post from the original code:zIRON forum.
does Ziron support static variable inside the function or procedure ?
http://www.freewebs.com/ogremagic/index.htm
what do you mean by static variables? global variables inside function? if yes then..
procedure myProc1() {
global int32 myInt;
myInt = 100;
return myInt;
}
procedure myProc2() {
global int32 myInt;
//nothing changed in this func, myInt should be 0 since it is not related to myProc1 myInt
return myInt;
}
eax = myProc1();
print('myProc1: ', eax:int, '\r\n');
eax = myProc2();
print('myProc2: ', eax:int, '\r\n');
each global inside a function will have their own version of myInt in a local scope.
the output should be:
myProc1: 100
myProc2: 0
maths functions such as add and so on need some work but another example
procedure myProc1() {
global int32 myInt;
//maths functions need work which i will do very shortly, for now simple mov add mov.
eax = myInt;
eax += 100;
myInt = eax;
}
procedure myProc2() {
global int32 myInt;
//nothing changed in this func, myInt should be 0 since it is not related to myProc1 myInt
return myInt;
}
eax = myProc1();
print('myProc1: ', eax:int, '\r\n');
eax = myProc2();
print('myProc2: ', eax:int, '\r\n');
eax = myProc1();
print('myProc1: ', eax:int, '\r\n');
output:
myProc1: 100
myProc2: 0
myProc1: 200
does #define directive works as in C&C++ , so i what to use static instead global statement?
http://www.freewebs.com/ogremagic/index.htm
static keyword is reserved for something else, that once it is corrected will be explained in detail via documentation.
and the #define keyword works different to c and c++, it only accepts a single parameter (for now)
#define ABC;
#define 1234;
check documentation via the menu for directives.