Page 1 of 1

Comptability between in C and PB for array

Posted: Mon Aug 12, 2024 8:14 am
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 ?

Re: Comptability between in C and PB for array

Posted: Mon Aug 12, 2024 10:10 am
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

Re: Comptability between in C and PB for array

Posted: Mon Aug 12, 2024 10:42 am
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.