bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 12 forks source link

Passing "varptr struct" to functions expecting byte ptr #553

Closed GWRon closed 3 years ago

GWRon commented 3 years ago

Think the code says it all already (it was written by our beloved @davecamp

Method New(worldAABB:sb2AABB, gravity:sb2Vec2, doSleep:Int)
  Local pworldAABB:Byte Ptr = Varptr worldAABB ' workaround
  Local pgravity:Byte Ptr = Varptr gravity     ' workaround
  b2ObjectPtr = bmx_b2world_create(pworldAABB, pgravity, doSleep)
  ' b2ObjectPtr = bmx_b2world_create(VarPtr worldAABB, VarPtr gravity, doSleep) ' why do I have to workaround this?
EndMethod

So : why can't we just "VarPtr mystruct" ?

GWRon commented 3 years ago
SuperStrict
Framework Brl.StandardIO

Function DoIt(s:STest)
    AssignMe(Varptr s)
End Function

Function AssignMe(p:Byte Ptr)
    Print "OK"
End Function

Struct STest
    Field x:Int
End Struct

DoIt(New STest)

results in

Compile Error: Unable to find overload for assignme(STest). Argument #1 is "STest" but declaration is "Byte Ptr"

@HurryStarfish and @woollybah - is this a bug in BCC or something which is "by design" not doable?

Edit: forgot to mention that replacing "struct" with "type" makes it compileable.

HurryStarfish commented 3 years ago

Yeah, that would be a bug. I see no reason why it shouldn't work for structs the same way as for primitives.