pass structure containing string to C code
type simcase
a::Int32
b::Int32
c::Cstring
end
n = 2
m = 3
x = randn(n,m)
s = simcase(3,4,Cstring("hello"))
ccall((:printArray, "./test_array.so"), Void, ( Ptr{Float64}, Int32, Int32, simcase), x, Int32(n), Int32(m), s)
produces:
julia> ERROR: LoadError: MethodError: Cannot `convert` an object of type String to an object of type Cstring
This may have arisen from a call to the constructor Cstring(...),
since type constructors fall back to convert methods.
in Cstring(::String) at ./sysimg.jl:53
in eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:64
in macro expansion at ./REPL.jl:95 [inlined]
in (::Base.REPL.##3#4{Base.REPL.REPLBackend})() at ./event.jl:68
while loading /home/nbecker/julia-test/test_array.jl, in expression starting on line 10
What’s the correct way to do this? I want the C code to get a structure containing a null-terminated C-string.