Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing array to macros
#1
I need to pass array into a function but with another thread. how to do it? way below doesn't work

Macro mac_t1
Code:
Copy      Help
int x(5)
ARRAY(int) y
y.create(2)
y[1]=6

mac "mac_t2" "" x y

Function mac_t2
Code:
Copy      Help
/
function x ARRAY(int)&y
out x
out y[1]
wait 10
#2
If the macro will not use the array after mac:
Macro mac_t1
Code:
Copy      Help
int x(5)
ARRAY(int)* p._new ;;creates array in heap memory, not on stack
ARRAY(int)& y=p
y.create(2)
y[1]=6

mac "mac_t2" "" x &y ;;passes pointer to the array, let the function delete it when don't need
Function mac_t2
Code:
Copy      Help
/
function x ARRAY(int)&y

atend sub.AutoDeleteArray &y

out x
out y[1]
wait 2


#sub AutoDeleteArray
function ARRAY(int)*p
p._delete
out "array deleted"

If the macro will use the array after mac, better use global variable:
Macro mac_t3
Code:
Copy      Help
int x(5)
ARRAY(int)+ g_y

lock g_y
g_y.create(2)
g_y[1]=6
lock- g_y

mac "mac_t4" "" x

wait 2
lock g_y
out g_y[1]
lock- g_y
Function mac_t4
Code:
Copy      Help
/
function x ARRAY(int)&y

ARRAY(int)+ g_y

out x

lock g_y
out g_y[1]
g_y[1]=7
lock- g_y

wait 1
#3
thx again


Forum Jump:


Users browsing this thread: 1 Guest(s)