# Is it possible to splat into ccall?

**URL:** https://discourse.julialang.org/t/is-it-possible-to-splat-into-ccall/95761
**Category:** General Usage
**Tags:** ccall
**Created:** [March 8, 2023, 7:49pm UTC](https://discourse.julialang.org/t/is-it-possible-to-splat-into-ccall/95761 "2023-03-08T19:49:46Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![lmtzx9h4qqnt](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@lmtzx9h4qqnt](https://discourse.julialang.org/u/lmtzx9h4qqnt)
#### Post date: [March 9, 2023, 8:07pm UTC](https://discourse.julialang.org/t/is-it-possible-to-splat-into-ccall/95761/6 "2023-03-09T20:07:00Z")

</div>

I’m aware of the importance of ensuring that functions are called with the correct signatures. There is nothing Julia can do to enforce this – when calling external functions, it’s the programmer’s responsibility to ensure that the function signature is defined correctly in Julia and that, for example, arguments correctly matching the format string are passed to functions like `printf`. And in C, this is just how it works – there is no way for `printf` to verify how many arguments were actually passed to it.

When it comes to making sure that the numbers of argument types and argument values are equal, there is no reason that it has to be done at a syntax level or at compile time – in the simplest case, `ccall` could just check if they match at runtime and throw an exception if they don’t. But this is really a flaw in the design of `ccall`: Why are the argument types and values passed separately? If they were passed together (which is exactly how it works with `@ccall`), there wouldn’t even be any need to check that the lengths match!

Rather, what I think is going on here is that this might be an accidental artifact of history rather than a conscious design decision. As @c42f explains in the thread I linked, `ccall` was created at a very early stage:

> [@Why is ccall syntax?](https://discourse.julialang.org/t/why-is-ccall-syntax/72427/3):
>
> #### The historical answer
> 
> `ccall` dates from _very_ early in Julia’s development. Perhaps around [this commit](https://github.com/JuliaLang/julia/commit/18f456233b280f2b5649c033c1977133c73bfd88) where it was first added to the runtime or [this commit](https://github.com/JuliaLang/julia/commit/e9fbc5c52ff123da27b9cc368b77372fa0618574) where the syntax became more similar to its current form.
> 
> This was back when Julia source code was still stored in `.j` files, and the first `ccall` commit was before macros were even implemented as part of [this commit](https://github.com/JuliaLang/julia/commit/a1b9fee4e72e8438693eddc25d769fab4cc98c9d).

Perhaps splatting in its current form just didn’t exist at the time, and `ccall` simply incorrectly interprets a splatting expression as a single argument? The error message is definitely incorrect and misleading:

```julia
ERROR: syntax: more types than arguments for ccall around REPL[65]:1

```

Also, note that in my example, it’s guaranteed even at compile time that the correct number of arguments is passed, because `args` is of type `NTuple{9, Integer}`.

---

_[View the full topic](https://discourse.julialang.org/t/is-it-possible-to-splat-into-ccall/95761)._
