Some questions about initialization

Monkey Forums/Monkey Programming/Some questions about initialization

Gerry Quinn(Posted 2012) [#1]
I have some questions about initialisation of variables and arrays, which don't seem to be mentioned anywhere in the documentation.

Are ints always initialised to 0 if declared without initialisation? What about floats?

I was looking at monkey.stack and it seems to rely upon this. Also it seems to depend on:

Local a:Int[]
a = a.Resize( 10 )


..which I wouldn't have expected to be allowed. But then again arrays are not objects, so this may be a beneficial side effect.

Can we rely on numeric values always being initialised to zero? And the resizeability of uninitialised arrays?

[I want to make a huge array of stacks, many of which will be discarded without being used, so the absence of any need for initialisation of the array component is a boost to efficiency.]


DruggedBunny(Posted 2012) [#2]
Yes, although not stated in the docs with regards to new variables, you can rely on all variables being initialised to 0/null defaults: false for bool, 0 for int and float, "" for string, [] for arrays and Null for objects.


Gerry Quinn(Posted 2012) [#3]
Cool, thanks!

[My application is an image-processing experiment. That must be why I just misread your sig as "Death to the Pixels!"]


Gerry Quinn(Posted 2012) [#4]
Double post deleted.


DruggedBunny(Posted 2012) [#5]
No way, I love pixels! The bigger the better!