# Using legacy C code with autodifferentiation

**URL:** <https://discourse.julialang.org/t/using-legacy-c-code-with-autodifferentiation/132548>\
**Category:** General Usage\
**Tags:** binarybuilder, c\
**Created:** [September 22, 2025, 1:21am UTC](https://discourse.julialang.org/t/using-legacy-c-code-with-autodifferentiation/132548 "2025-09-22T01:21:17Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![hersle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hersle/32/211689_2.png) [@hersle](https://discourse.julialang.org/u/hersle)\
**Post date:** [October 28, 2025, 4:31pm UTC](https://discourse.julialang.org/t/using-legacy-c-code-with-autodifferentiation/132548/5 "2025-10-28T16:31:56Z")

</div>

To differentiate through CLASS and make it compatible with Enzyme, should one perhaps look to modify it so there is a pure C function that one can `ccall` from Julia (like [here](https://discourse.julialang.org/t/calling-c-code-with-automatic-differentiation-in-julia/129503/6)) to return the desired output as a function of some given input parameters? Maybe something like this:

```C
void output_from_input(double *output, double *input) {
   // populate output from input
}

```

If so, that would require circumventing the standard interface with `*.ini` input configuration files and `*.dat` output data files.

I think it would be very interesting to try to start with something trivial, say just computing \Omega\_{c0}(\omega\_{c0}) = \omega\_{c0}/h^2 as a function of \omega\_{c0} (and some fixed h). Then, if that works, one could try to include more parameters and ramp up autodiff module-by-module (background, thermodynamics, perturbations, …) and ultimately get the C\_l for the CMB as a function of some parameters or something similar.

---

_[View the full topic](https://discourse.julialang.org/t/using-legacy-c-code-with-autodifferentiation/132548)._
