# Ccall when argtype is a struct

**URL:** https://discourse.julialang.org/t/ccall-when-argtype-is-a-struct/36328
**Category:** General Usage
**Tags:** ccall
**Created:** [March 22, 2020, 1:48am UTC](https://discourse.julialang.org/t/ccall-when-argtype-is-a-struct/36328 "2020-03-22T01:48:05Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![iloaiza](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iloaiza](https://discourse.julialang.org/u/iloaiza)
#### Post date: [March 22, 2020, 1:48am UTC](https://discourse.julialang.org/t/ccall-when-argtype-is-a-struct/36328/1 "2020-03-22T01:48:05Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [March 22, 2020, 2:08am UTC](https://discourse.julialang.org/t/ccall-when-argtype-is-a-struct/36328/2 "2020-03-22T02:08:37Z")

</div>

> [@iloaiza](#):
>
> Julia structure with the same names and pattern

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

> [@iloaiza](#):
>
> 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?

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.

---

<div class="post-metadata">

### Author: ![iloaiza](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iloaiza](https://discourse.julialang.org/u/iloaiza)
#### Post date: [March 25, 2020, 12:13am UTC](https://discourse.julialang.org/t/ccall-when-argtype-is-a-struct/36328/3 "2020-03-25T00:13:40Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [March 25, 2020, 1:00am UTC](https://discourse.julialang.org/t/ccall-when-argtype-is-a-struct/36328/4 "2020-03-25T01:00:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![iloaiza](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iloaiza](https://discourse.julialang.org/u/iloaiza)
#### Post date: [March 25, 2020, 2:55am UTC](https://discourse.julialang.org/t/ccall-when-argtype-is-a-struct/36328/5 "2020-03-25T02:55:12Z")

</div>

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