# @cfunction with variable arguments

**URL:** https://discourse.julialang.org/t/cfunction-with-variable-arguments/17994
**Category:** New to Julia
**Tags:** ccall
**Created:** [November 25, 2018, 11:29pm UTC](https://discourse.julialang.org/t/cfunction-with-variable-arguments/17994 "2018-11-25T23:29:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![darthead](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@darthead](https://discourse.julialang.org/u/darthead)
#### Post date: [November 25, 2018, 11:29pm UTC](https://discourse.julialang.org/t/cfunction-with-variable-arguments/17994/1 "2018-11-25T23:29:17Z")

</div>

I am currently trying to adapt some old code with deprecated features for julia 1.0.  
Currently, I am stuck trying to implement the new @cfunction macro functionality.

The code I’m trying to adapt is the following:

```julia
function create_cfunction(f, r, a)
# run some checks
    cfunction(f, r, a)
end

```

which is currently called with a function f, its return type r and a tuple of arguments, eg.

```julia
create_cfunction(f, Float64, (Float64, Float64))

```

First of all, I corrected the code according to the first warning and changed the corresponding line successfully to

```julia
cfunction(f, r, Tuple{a...})

```

However, the second deprecation warning mentioned the change to the macro `@cfunction`. Simply changing to that however doesn’t work, as the macro seems to expect a literal tuple instead of a variable one as is being used in the code above. Is there a method of working around this restriction or is trying to do that disapproved of (eg. for performance reasons)?

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [November 26, 2018, 3:49am UTC](https://discourse.julialang.org/t/cfunction-with-variable-arguments/17994/2 "2018-11-26T03:49:38Z")

</div>

Does the following, from the docstring of `@cfunction`, help?

> Note that the argument type tuple must be a literal tuple, and not a tuple-valued variable or expression (although it can include a splat expression). And that these arguments will be evaluated in global scope during compile-time (not deferred until runtime). Adding a ‘$’ in front of the function argument changes this to instead create a runtime closure over the local variable callable.

---

<div class="post-metadata">

### Author: ![darthead](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@darthead](https://discourse.julialang.org/u/darthead)
#### Post date: [November 26, 2018, 8:37am UTC](https://discourse.julialang.org/t/cfunction-with-variable-arguments/17994/3 "2018-11-26T08:37:37Z")

</div>

Thank you for hinting at the docstring, I have in fact only read the corresponding manual chapter but not the docstring itself as it seems…  
However, since this is regarding only the function argument and not the return value and argument tuple, it does not help me at all.

To me it also seems ambiguous whether or not to use `@eval` in front of this call, as the docstring just says “Adding a ‘$’ in front of the function argument”, whereas the manual section does similar to the ccall arguments using `@eval` (albeit to the name and library arguments - it does however state that `@cfunction` usage is “similar”)  
Again to clarify: `cfunction(f, r, Tuple{a...})` does work and a is taking values like `(Float64,)` or `(Float64,Float64)`.  
As I was unsure about using `@eval` or not, I tried both and it also failed, this time at runtime (at function call) with an `ArgumentError`.

---

<div class="post-metadata">

### Author: ![darthead](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@darthead](https://discourse.julialang.org/u/darthead)
#### Post date: [December 2, 2018, 7:37pm UTC](https://discourse.julialang.org/t/cfunction-with-variable-arguments/17994/4 "2018-12-02T19:37:16Z")

</div>

It seems like I may have posted into a wrong subforum. I would like to kindly ask a privileged user to move my topic to the correct subforum and delete this message as it has then become irrelevant.
