Skip to content
Low-level programming · Higher-level thinking
Login Register
Forum / Requests and Feedback

static variable in function

A community discussion post from the original code:zIRON forum.

Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

static variable in function

does Ziron support static variable inside the function or procedure ?

http://www.freewebs.com/ogremagic/index.htm

Replies

Colin admin
Posts
928
Threads
49
Location
Bulgaria

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
Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

well , that waht i am asking for.

thanks.

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

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
Emil_halim member
Posts
639
Threads
104
Location
Alex, Egypt

does #define directive works as in C&C++ , so i what to use static instead global statement?

http://www.freewebs.com/ogremagic/index.htm

Colin admin
Posts
928
Threads
49
Location
Bulgaria

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.