# Passing function pointer to Cxx

**URL:** <https://discourse.julialang.org/t/passing-function-pointer-to-cxx/1159>\
**Category:** General Usage\
**Tags:** cxx\
**Created:** [December 27, 2016, 8:22am UTC](https://discourse.julialang.org/t/passing-function-pointer-to-cxx/1159 "2016-12-27T08:22:02Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![groot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/groot/32/13081_2.png) [@groot](https://discourse.julialang.org/u/groot)\
**Post date:** [December 1, 2018, 9:36pm UTC](https://discourse.julialang.org/t/passing-function-pointer-to-cxx/1159/6 "2018-12-01T21:36:35Z")

</div>

For anyone that is interested doing this

```julia
using Cxx

cxx"""
void evaluatec(void (*f)() ){
    f();
}
"""

function evaluate(f)
    f_void_ptr = @cfunction($f, Cvoid, ()) # void pointer on f. Need to cast it to function pointer
    f_void_ptr2 = f_void_ptr.ptr
    #show(typeof(f_void_ptr))
    icxx"""
    typedef void (*fptr)();
    fptr f_fun_ptr = reinterpret_cast<fptr>($f_void_ptr2);
    evaluatec(f_fun_ptr);
    """
end

f() = println("hi")
evaluate(f)

g() = print("ho")
evaluate(g)

```

works under 1.0.2

---

_[View the full topic](https://discourse.julialang.org/t/passing-function-pointer-to-cxx/1159)._
