Page 1 of 1

C Array to PB

Posted: Tue Sep 16, 2008 10:32 pm
by Lazarus404
Hey guys,

Okay, so, I'm consuming a C function which returns a pointer to a list of objects that I already have a structure for. I also know the number of objects in the list, but I don't know how to pass it to a PB variable so it can be treated as an array. For example, imagine my C function returned an array integers such as

Code: Select all

int* get_array_ptr( obj* array );
Now, in my PB code, how would I pass that into a PB variable? Currently, I've tried this, but it doesn't work

Code: Select all

Dim pba.l( get_array_size( *arr ) ) = get_array_ptr( *arr )
I've also tried this

Code: Select all

Dim pba.l( get_array_size( *arr ) )
pba = get_array_ptr( *arr )
And various other ways... What is the correct way?

Thanks,

Posted: Tue Sep 16, 2008 10:44 pm
by tinman
Pointers to arrays can be done with structures containing arrays with zero elements.

Code: Select all

Structure LongArray
    l.l[0]
EndStructure

*foo.LongArray = get_array_ptr(*arr)

; *foo\l[0] etc can now be accessed as elements of the array

Posted: Wed Sep 17, 2008 10:31 am
by Lazarus404
Thanks, Tinman... Yet again, you've helped loads :D