C Array to PB

Just starting out? Need help? Post your questions and find answers here.
Lazarus404
User
User
Posts: 74
Joined: Fri Dec 02, 2005 3:11 pm
Location: England
Contact:

C Array to PB

Post 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,
Laz

Registered PureBasic user since Nov 2005
Check out FlashML at www.designrealm.co.uk... The ultimate Flash Component
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Lazarus404
User
User
Posts: 74
Joined: Fri Dec 02, 2005 3:11 pm
Location: England
Contact:

Post by Lazarus404 »

Thanks, Tinman... Yet again, you've helped loads :D
Laz

Registered PureBasic user since Nov 2005
Check out FlashML at www.designrealm.co.uk... The ultimate Flash Component
Post Reply