[Gambas-user] Array constant
Grahame White
grahame at ...457...
Tue May 25 22:35:58 CEST 2004
> > PUBLIC CONST POW2 AS Short[] = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
> >
> > or something in this mind.
>
> Do it by hand in the static constructor _init().
>
> STATIC PUBLIC POW2 AS Short[]
>
> STATIC PUBLIC SUB _init()
>
> POW2 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
>
> END
>
> > I've another question.... what about the TYPE keyword ?
>
> There is no TYPE keyword !?
I tried it your way and I think it uncovered a small bug. When I tried it
declaring POW2 as short[] I got an error message about a datatype
mismatch, it was expecting an integer and got a short instead. I stepped
through the program line by line with the debugger and when it got to
POW2 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
it produced the error again. So I declared POW2 as integer[] and my program
ran fine.
I was a little puzzled so I looked through the docs and found this
array = Array ( Expression , ... )
Creates an array and returns it. The type of the array is the type of the
first expression. The other expressions are automatically converted.
This seems to explain what is going on as the first value is 1 which I'm
guessing is being detected as an integer so when I pass it a short it
throws up the error.
Grahame
More information about the User
mailing list