[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: varptr to structs returns bad pointer value


> In my opinion, Jussi, in these cases the best solution is the one you
> proposed:
>
> https://lists.gambas-basic.org/archive/user/2025-02/0000234.html
>

No, this is not suitable. I suggested it before understanding he needed to
pass generic structure (IE pointer to some structure that might change).


> ..In fact, my suggested code involves a “global” statement.

Yes, I know. You are missing the context.


This is the correct solution:

extern myFunction(data as pointer) use "mylib"
public dataSet as pointer
public struct myStruct
     result as long
     msg as string
end struct
public mydata as mystruct

this works as expected

public sub doit()
   dataSet = alloc(sizeof(mystruct))
   mydata = dataSet
   myFunction(dataSet)  ' this works
end sub

this fails

public sub doit2()
   mydata = new myStruct
   dataSet = Object.Data(myData)
   myFunction(dataSet)  'This should also.
end sub



Jussi

Follow-Ups:
Re: varptr to structs returns bad pointer valueBrian G <brian@xxxxxxxxxxxxxxxx>
References:
Re: varptr to structs returns bad pointer valueBenoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
Re: varptr to structs returns bad pointer valueJussi Lahtinen <jussi.lahtinen@xxxxxxxxx>
Re: varptr to structs returns bad pointer valuevuott@xxxxxxxxxxxx