Array initialisation

BlitzMax Forums/BlitzMax Programming/Array initialisation

Global array1:Short[] = [1,2,3]
Global array2:Byte[] = [1,2,3]

Compiler error: "Unable convert 'int array' to 'short/byte array'"

put :byte and :short behind them.
what you have there are int arrays.

Please post a working sample(if it's really exist) this is not big source.
BTW
Global array1:Short[] = Short[1,2,3]
'or
Global array1:Short[] = [1,2,3]:Short
- not right.
And direct typecasting for each element is so weird.

Oh, Dreamora, you right, but this is direct typecasting. I use it other form as 'Byte(...)/short(...)' for each element. But this is not a good idea - i needs a huge array and write type for each element is very very bad.

Both is wrong, seems like you haven't used direct type declaration on numerics so:

global array1:short[]= [1:short, 2:short, 3:short]


I understand you, but direct typecasting for each element is not a good idea if we have a huge array.
BTW this is a bit stupid - declare array as short and declare type individually to each element of array.
May be this songs as 'feature request', but i think this is compiler bug or miss.

Initializing an array that way is a bad idea anyway.
It is slow, 3-10 times slower than

global array1:short[] = new short[3]
array1[0] = 1
array1[1] = 2
array1[2] = 3


and the problem gets larger the larger the array is you assign.
You know, arrays in a managed environment are a little a different thing than in C++, where they are just a continous block of memory that you can create with memalloc and its done. (in BM an array of any types are extended of the class ARRAY actually)

This is by design.

Thanks