Static variables inside functions
Posted: 26 Sep 2021, 18:01
What differs
from
Does static inside a function implies it will be initialized just once before script begins (or when the function is called)?
Calling a function with static variables multiple times, will assign the variables again?
Code: Select all
MyFunction() {
static TargetVar, RequestedCapacity = 16
VarSetCapacity(TargetVar, RequestedCapacity, 0)
NumPut(RequestedCapacity , TargetVar, 0, "Type")
DllCall("Function", "Ptr", &TargetVar)
Flag := NumGet(TargetVar, 8, "Type")
return Flag
}
Code: Select all
MyFunction() {
RequestedCapacity = 16
NumPut(RequestedCapacity , TargetVar, 0, "Type")
VarSetCapacity(TargetVar, RequestedCapacity, 0)
DllCall("Function", "Ptr", &TargetVar)
Flag := NumGet(TargetVar, 8, "Type")
return Flag
}
Calling a function with static variables multiple times, will assign the variables again?