Ccall when argtype is a struct

Hey guys!
I am trying to write my own small module to interface a C package to my existing Julia code. This C package is working, and I have compiled it with all the necessary flags so it’s a .so file. My problem is that one of the inputs for a function that I have to call uses a structure which is defined inside of the C package. The struct is defined by a long chain of ints, doubles and a pointer to a double :
‘’’
int max_deg;
int min_deg ;
int damping;
double thresh_ext;
double thresh_int;
double intvtol;
int type;
double *mu;
double cc;
double dd;
double gam;
double bar;
int deg ;
‘’’

Should I build a Julia structure with the same names and pattern and use it as input type? I’m not sure how I should write the Julia function which uses ccall to do this.

Also, if in general I’ll have to interface the code with other functions which use structs that may also have a pointer to a couple of arrays, so I guess if my general question would be how to interface the ccall with a generic type using ccall?

Thanks a lot for your help :slight_smile:

Not name, you just need identical field types. And then you just pass that struct to the ccall.

There’s no “generic type” in C (and therefore ccall) You always just write the ccall to match the C type and there’s nothing more generic than that. If what you are worrying about is pointers, then you need to get that pointer and fill it into the struct you create while maintaining the validity of the object you obtained the pointer from.

Awesome, thanks a lot! After reading this the ccall documentation made more sense (and I now realize it basically had the answer haha, I really should read that better before annoying people on this forum).
Anyways, thanks again!

If you can think of any way the documentation would be clearer, it would be great to get a pull request with an update. New users who just figured something out are the perfect people to improve documentation since they both understand the material and know best what a new user would want from it.

Hadn’t thought of this. I’ll make a pull request :slight_smile: