# Passing a Julia function to C, with a double\* input argument

**URL:** https://discourse.julialang.org/t/passing-a-julia-function-to-c-with-a-double-input-argument/51966
**Category:** General Usage
**Tags:** ccall
**Created:** [December 17, 2020, 9:57am UTC](https://discourse.julialang.org/t/passing-a-julia-function-to-c-with-a-double-input-argument/51966 "2020-12-17T09:57:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stla/32/20382_2.png) [@stla](https://discourse.julialang.org/u/stla)
#### Post date: [December 17, 2020, 9:57am UTC](https://discourse.julialang.org/t/passing-a-julia-function-to-c-with-a-double-input-argument/51966/1 "2020-12-17T09:57:14Z")

</div>

Hello,

I have to pass a Julia function to C. The C function has one input argument: a `double*`.

For example

```julia
function myfun(x)
  return sum(x)
end

```

What is the way? Is it that:

```julia
myfun_c = @cfunction(myfun, Cdouble, (Ref{Ptr{Cdouble}}, ))

```

?

Thank you.

---

<div class="post-metadata">

### Author: ![stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stla/32/20382_2.png) [@stla](https://discourse.julialang.org/u/stla)
#### Post date: [December 17, 2020, 11:34am UTC](https://discourse.julialang.org/t/passing-a-julia-function-to-c-with-a-double-input-argument/51966/2 "2020-12-17T11:34:27Z")

</div>

I get it 🙂

```julia
function pdf(xy)
    x = unsafe_load(xy, 1)
    y = unsafe_load(xy, 2)
    return exp(-x*x -y*y)::Cdouble
end

pdf_c = @cfunction(pdf, Cdouble, (Ptr{Cdouble}, ))

```
