Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/overhertz/domains/codeziron.com/public_html/ziron/ziron.db.connector.php on line 13 code:zIRON - Get the latest releases plus source-codes and tutorials - Simplifed Assembly Programming Language.
Register | Login
Forum Index > Requests and Feedback > static variable in function
Author Message
Pages: 1
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 638
Topics: 103

Location:
Alex, Egypt
[156] static variable in function - posted: 2011-10-27 19:18:39

does Ziron support static variable inside the function or procedure ?

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

avatar

(send private message)

Posts: 925
Topics: 54

Location:
OverHertz Studio
[157] - posted: 2011-10-27 19:40:18
what do you mean by static variables? global variables inside function? if yes then..

Code:
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:

Code:
myProc1: 100
myProc2: 0


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 638
Topics: 103

Location:
Alex, Egypt
[158] - posted: 2011-10-27 19:42:13
well , that waht i am asking for.

thanks.


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

avatar

(send private message)

Posts: 925
Topics: 54

Location:
OverHertz Studio
[159] - posted: 2011-10-27 19:46:37
maths functions such as add and so on need some work but another example

Code:
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:
Code:
myProc1: 100
myProc2: 0
myProc1: 200


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Emil_halim
Ziron Beta Tester

avatar

(send private message)

Posts: 638
Topics: 103

Location:
Alex, Egypt
[160] - posted: 2011-10-27 19:52:38

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

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

avatar

(send private message)

Posts: 925
Topics: 54

Location:
OverHertz Studio
[168] - posted: 2011-10-27 20:32:25
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.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 1 user(s) online. 0 member(s) and 1 guest(s)
Most users ever online was 999, May 11, 2018, 9:01 am.


Statistics:
Threads: 223 | Posts: 1837 | Members: 50 | Active Members: 50
Welcome to our newest member, NobodyAtWork
const Copyright = '2011-2018 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd