Hi Steven, thank you very much for the clarification. It was indeed possible to pass the length if the vector and with pointer_to_array it works smoothly.
Tomas On Tuesday, 2 August 2016 13:46:47 UTC+2, Steven G. Johnson wrote: > > > > On Tuesday, August 2, 2016 at 7:39:16 AM UTC-4, [email protected] wrote: >> >> Hi All, >> I am trying to bind a fortran library for optimization ( >> http://napsu.karmitsa.fi/lmbm/) to Julia. >> To do so, I would like to get a pointer to function written in Julia, >> which I try to do as >> >> function fOpt(x::Array{Float64,1},g::Array{Float64,1}) >> fill!(g,1.0); >> convert(Cdouble,sum(x))::Cdouble >> end >> const fOptPtr = cfunction(fOpt, Cdouble, (Ptr{Cdouble}, Ptr{Cdouble})) >> >> > An Array{T} is not the same thing as a Ptr{T}. > > You need to declare fOpt to take Ptr{Cdouble} arguments. You can use the > pointer_to_array function to convert pointers to Arrays. (However, you > need to know the length of the array; I'm surprised that the length is not > passed as an argument — are you supposed to use a global?) >
