Comptability between in C and PB for array

Just starting out? Need help? Post your questions and find answers here.
threedslider
Enthusiast
Enthusiast
Posts: 396
Joined: Sat Feb 12, 2022 7:15 pm

Comptability between in C and PB for array

Post by threedslider »

PB doesn't know how to handle array in C when I have imported from C Lib with my function m_array().

See my examples here : https://drive.google.com/file/d/1uO2e_O ... sp=sharing

My code is here :

Code: Select all

CompilerIf #PB_Compiler_OS <> #PB_OS_Windows
    CompilerError "This example is working on Windows only and in console mode"
CompilerEndIf


Import "Array.lib"
  ;my_array(Array mem(1), number.i)
EndImport


Dim mem.i(5)

mem(0) = 15
mem(1) = 1
mem(2) = 350
mem(3) = 25
mem(4) = 55


;; Working for array
!int mem[] = {15, 1, 350, 25, 55}; 


OpenConsole()

;False position of number int
;!my_array(a_mem, 5); 

;Working for array
!my_array(mem, 5);

;my_array(mem(), 5) ;; Not working for Dim

Input()

CloseConsole()
Is it a bug or what ? Or it doesn't support yet for access with array in PB to C ?
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Comptability between in C and PB for array

Post by StarBootics »

The C array you are creating is 'Static' while PureBasic Array are 'Dynamic'. They are incompatible data structures, that's why your code don't work.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
threedslider
Enthusiast
Enthusiast
Posts: 396
Joined: Sat Feb 12, 2022 7:15 pm

Re: Comptability between in C and PB for array

Post by threedslider »

StarBootics wrote: Mon Aug 12, 2024 10:10 am The C array you are creating is 'Static' while PureBasic Array are 'Dynamic'. They are incompatible data structures, that's why your code don't work.

Best regards
StarBootics
Ok I understand, only C backend works on it.

Thank you.
Post Reply