Multiple identifiers
BlitzMax Forums/BlitzMax Programming/Multiple identifiers
| ||
| Hello, There is one thing about BMax that still confuses me: how to make more than one identifier pointing on the same variable so that i can modify this single variable using any of them? The rough idea: ------- a=1 b=a b=b+1 print a ------ and have the printed text be "2". Don't hesitate to ask if i didn't make me clear. Thanks in advance for your answers! |
| ||
| For simple basic types as Int, float, double, you can't do this. What is possible is to use var in function headers:
bar = 1
foo(bar)
print bar
function foo(bar:int var)
bar:+1
end function
Objects always are treated as references, so will behave like you want it to. |
| ||
| You can do it with pointers. local a:Int=1 local b:Int Ptr=VarPtr(a) b[0]:+1 print a |
| ||
| Thank you very much for your quick and useful answers! :-) NB: Pointers don't work with custom types. For object, only fields seems to work this way (if you nullify the second object variable, the first will still be there). |