I have just started with Julia and need to invoke an external C library
that has used the "struct hack <http://c-faq.com/struct/structhack.html>"
to represent a string. How do I retrieve the string in Julia? I've ported
the example from the linked FAQ entry and tried this code:
immutable Name
Namelen::Int32
Namestr::Uint8
end
const clib = dlopen("libstructtest")
bob = convert(Ptr{Uint8}, "Bob")
namePtr = ccall(dlsym(clib, :makename), Ptr{Name}, (Ptr{Uint8},), bob)
name = unsafe_load(namePtr)
println(name.Namelen)
println(name.Namestr)
This code will display the ASCII code of the first character (65=B), but
how do you iterate over the remainder? I've also tried other approaches
including Namestr::Ptr{Uint8}, unsafe_load of the Namestr when a Pointer,
bytestring etc. Any suggestions appreciated.
Thanks
Ben