This does the same thing right?

BlitzMax Forums/BlitzMax Programming/This does the same thing right?

Leiden(Posted 2006) [#1]
Function Test(t:float[])
End Function

Function Test(t:float ptr)
End Function


So its safe to assume either implementation is correct?

*One step close to understaning pointers* - I've always used em in C++, but never understood what they were.


ImaginaryHuman(Posted 2006) [#2]
the label for a float array is actually a float ptr behind the scenes so it should be ok

Within the second function you could do
Print t[0] to print the first float from the array


Leiden(Posted 2006) [#3]
I could also use Print t[0] in the first Function too right?

So the correct definition for an array is something like: "A pointer to the first element"?


SculptureOfSoul(Posted 2006) [#4]
arrays are treated as objects in Bmax and have a length field, so it's not truly "the same thing" although, the indexing methods are the same (as AngelDaniel mentioned.)

Strict

Global blah:Float[] = New Float[25]
blah[1] = 53235

Function test(obj:Object)
Print Float[](obj)[1] 'the cast is necessary because you can't index an object
EndFunction

test(blah)


Traditionally an array is just a pointer to the first element, correct. Of course, there is some "behind the scenes stuff too", the compiler stores the size of the array somewhere ( array.length in Bmax).


Leiden(Posted 2006) [#5]
Ahh ok, more understandable now. Thanks guys.


FlameDuck(Posted 2006) [#6]
So its safe to assume either implementation is correct?
No. One is managed (the array) and the other is not (the pointer).