Posts: 684
Threads: 64
Joined: May 2004
I've done this before, but it's not working this time. Here is my error:
Code:
game.bi(15) : error 57: Illegal specification, at parameter 1: list
Declare Sub EraseBricks(list() As PointType)
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Posts: 324
Threads: 12
Joined: Nov 2005
Are you sure PointType has been declared before this function declaration?
stylin:
Posts: 684
Threads: 64
Joined: May 2004
Woops :oops:. Now that i've fixed that... Are you not allowed to DIMension an array (more specifically a dynamic array) inside a SUB or Function?
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Posts: 324
Threads: 12
Joined: Nov 2005
You sure can:
Code:
sub foo(dynamicSize as integer)
'/ declare fixed-size array
const staticSize as integer = 420
dim as integer staticBar(staticSize)
'/ declare variable-size array
dim as integer bar(dynamicSize)
end sub
staticSize must be a compile-time constant, of course (
const,
enum or literal).
stylin:
Posts: 1,407
Threads: 117
Joined: Dec 2002
Don't forget the arrays DIMed in subs/functions are created on the stack, and the stack is 1Mb by default.
If you need a bigger array either you make it shared, increase the stack size or use direct memory allocation.
Antoni
Posts: 357
Threads: 118
Joined: Oct 2004
You can also make a memory block act like an array.
Code:
Declare Function newInt(size as uinteger) as integer ptr
Declare Sub delete(pointr as integer ptr)
dim myArray as integer ptr
myArray = newInt(200)
for i = 0 to 200
myArray[i] = RND * 1000
next
delete myArray
Function newInt(size as uinteger) as integer ptr
return allocate(size * 4)
End Function
Sub delete(pointr as integer ptr)
deallocate pointr
End Sub
Ah, dynamic allocation
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
Posts: 324
Threads: 12
Joined: Nov 2005
Be careful using literals for datatype size like that. You should always prefer sizeof or len. I prefer sizeof myself, simply because it seems more compile-time to me, as len is also a run-time function. But they both give compile-time results for var and datatype sizes.
stylin: