Posts: 149
Threads: 32
Joined: Feb 2005
Code:
redim OperatorStack () as Ubyte
dim i as integer
redim OperatorStack (10) as Ubyte
for i = 0 to 10
OperatorStack(i) = i
next i
sleep
redim OperatorStack (20) as Ubyte
for i = 0 to 19
? i, OperatorStack(i)
next i
I was looking to see if redim in FB had a preserve nature to it. When I ran something similar to the above (and the above), it prints the numbers and then I get a lovely little error message on WinXP Pro. What gives?
Posts: 1,272
Threads: 36
Joined: Feb 2003
At least it doesn't crash on Linux, though it doesn't print anything.
I played around with the code a bit - I can't get it to work.
Posts: 268
Threads: 9
Joined: Dec 2004
It works as it should, i.e. waits a keypress, then prints the entries. Linux, FB CVS version.
By default redim does not preserve the array contents when redimensioning; to get what you want, your redim line should be changed to:
Code:
redim preserve OperatorStack (20) as Ubyte
Posts: 149
Threads: 32
Joined: Feb 2005
Code:
declare sub QuickCheck(dummy as string)
? "Start"
QuickCheck "Dummy"
sleep
end
sub QuickCheck (dummy as string)
redim OperatorStack () as Ubyte
dim i as integer
redim OperatorStack (10) as Ubyte
for i = 0 to 10
OperatorStack(i) = i
next i
sleep
redim OperatorStack (20) as Ubyte
for i = 0 to 19
? i, OperatorStack(i)
next i
end sub
When I ran the code by itself it doesn't crash, BUT when I put it in a subroutine (like I had it before, I just didn't post that part) it does crash.
Posts: 149
Threads: 32
Joined: Feb 2005
Quote:By default redim does not preserve the array contents when redimensioning; to get what you want, your redim line should be changed to:
Code:
redim preserve OperatorStack (20) as Ubyte
Yes, I am familiar with that format, I was just playing around with the REDIM statement when I came across the problem.
Posts: 922
Threads: 15
Joined: Jun 2003
Another one i missed..
DIM|REDIM array w/o explicit dimensions won't be allowed anymore inside procs, as the descriptor size is unknown, making it impossible (the way the compiler works) to reserve the right amount of space for each variable on stack.
I could just assume the array had the max number of dimensions allowed (16), but that would waste memory and "DIM|REDIM array()" is just "aesthetic", as it does nothing -- but it looks better when declaring dynamic shared arrays on modules, that used to be done with "REDIM array( 0 )" that will waste code as the module main-level is never called ("DIM array()" looks better :P).