# Passing a C struct into Julia

**URL:** <https://discourse.julialang.org/t/passing-a-c-struct-into-julia/43965>\
**Category:** General Usage\
**Tags:** memory-allocation, struct\
**Created:** [July 30, 2020, 11:06am UTC](https://discourse.julialang.org/t/passing-a-c-struct-into-julia/43965 "2020-07-30T11:06:28Z")\
**Posts on this page:** 1\
**Showing post:** 20

<div class="post-metadata">

**Author:** ![barnett567](https://avatars.discourse-cdn.com/v4/letter/b/e0b2c6/32.png) [@barnett567](https://discourse.julialang.org/u/barnett567)\
**Post date:** [February 2, 2021, 4:56pm UTC](https://discourse.julialang.org/t/passing-a-c-struct-into-julia/43965/20 "2021-02-02T16:56:38Z")

</div>

Dear Stefan & co,

Just to answer your final question as to _why_ we want to call Julia from C (or Fortran): It is _essential_ if Julia libraries are to be used with existing scientific codebases. One does not always have the luxury of declaring that Julia be the top-level/driver language 🙂 If I am to write Julia code, Fortran users need to be able to call it, just like we’ve had C-Fortran interoperability for decades. (With MATLAB, this cannot be done, driving my move towards Julia.) I have a set of minimal demos of this task on github, but I’m finding it a challenge:

> [@I made examples of wrapping jl code from Fortran & C; how generalize?](https://discourse.julialang.org/t/i-made-examples-of-wrapping-jl-code-from-fortran-c-how-generalize/52622):
>
> I am interested in calling Julia from Fortran (eg F90), and since I couldn’t find any, I built an example of that which goes through a C wrapper layer; see here: [https://github.com/ahbarnett/multilingual-julia](https://github.com/ahbarnett/multilingual-julia) It adapts code from the manual (Ch 30: Embedding) plus a SO post which explains how to call general J code. F is responsible for preallocating output arrays, in the classical F style. Multithreading works. It works but feels too clunky, involving text commands and a lot of jl\_\* calls pa…

What I’m really missing is a set of @cfunction usage examples with arrays. Any pointers (pun indended) welcome 🙂  
Best wishes, Alex

---

_[View the full topic](https://discourse.julialang.org/t/passing-a-c-struct-into-julia/43965)._
