Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array as a parameter?
#1
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]
Reply
#2
Are you sure PointType has been declared before this function declaration?
stylin:
Reply
#3
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]
Reply
#4
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:
Reply
#5
since .16, you can also do this


Code:
sub foo()

  dim as integer ary()

  ...

  redim ary( 7162 )

  ...

end sub

before you could not specify "dimensionless" arrays inside of sub/funcs
Reply
#6
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
Reply
#7
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 Smile
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.
Reply
#8
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:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)