Dear group,
 I am trying to write an interface to a c library that reads data files in 
a particular format. One of the pieces of data I am trying to read is a 
string, encoded like this:

typedef struct {
                INT16 len;
                char c;
               } LSTRING;


This is string is a member of larger structure

typedef struct  {

                   ... a bunch of simple bit types
                  LSTRING *message;
          } FEVENT 

I have created a Julia type that maps to this structure, where the LSTRING 
type is defined like this

type LSTRING
    len::Int16
    c::Uint8
end


Using ccall, I can successfully extract the FEVENT structure from the file. 
but of course the message field is returned as a pointer. My questions is 
how can I follow this pointer to get the actual data of the string? In an 
example written in C, the string is extracted by reading an array starting 
at the address of the field 'c' in LSTRING. 
Initially, I was using unsafe_load to copy the data that '*message' points 
to, but then I lose the original memory location of 'c'. 

Is there a way for me to do C-style pointer arithmetic in Julia to get the 
data from my string. Something like this?

char *msg = &(fevent->message->c);


Any insight into this would be greatly appreciated. I suppose I could write 
the code to access LSTRING in C, but I was hoping to avoid that.
 

 

 

Reply via email to