# Passing NULL as an argument through ccall?

**URL:** https://discourse.julialang.org/t/passing-null-as-an-argument-through-ccall/6190
**Category:** General Usage
**Created:** [October 2, 2017, 3:53am UTC](https://discourse.julialang.org/t/passing-null-as-an-argument-through-ccall/6190 "2017-10-02T03:53:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)
#### Post date: [October 2, 2017, 3:53am UTC](https://discourse.julialang.org/t/passing-null-as-an-argument-through-ccall/6190/1 "2017-10-02T03:53:21Z")

</div>

I cannot seem to figure out how to pass NULL as an argument to a function through the C interface.

I’m using Ref{UInt8} as the argument type.

I’m thinking that I could probably declare it as an Int and just pass 0, but of course the argument could in fact be a valid pointer to data i’ve created in julia.

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [October 2, 2017, 4:22am UTC](https://discourse.julialang.org/t/passing-null-as-an-argument-through-ccall/6190/2 "2017-10-02T04:22:35Z")

</div>

`Ptr{UInt8}(0)`

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [October 2, 2017, 12:27pm UTC](https://discourse.julialang.org/t/passing-null-as-an-argument-through-ccall/6190/3 "2017-10-02T12:27:05Z")

</div>

`C_NULL` or `Ptr{UInt8}(C_NULL)` would probably be clearer.

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [October 2, 2017, 12:42pm UTC](https://discourse.julialang.org/t/passing-null-as-an-argument-through-ccall/6190/4 "2017-10-02T12:42:16Z")

</div>

`C_NULL` doesn’t work.

---

<div class="post-metadata">

### Author: ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)
#### Post date: [October 2, 2017, 4:34pm UTC](https://discourse.julialang.org/t/passing-null-as-an-argument-through-ccall/6190/5 "2017-10-02T16:34:44Z")

</div>

No, `C_NULL` alone does not work, but `Ptr{UInt8}(C_NULL)` does.

Here is an interesting thing. I define my argument as:

```julia
Ref{UInt32}

```

and

```julia
Ptr{UInt32}(0)

```

works perfectly as expected, but if I use…

```julia
Ptr{UInt}(0)
Ptr{UInt8}(0)

```

I get a non-zero value for the pointer (!) and no complaints from julia in either case that I’ve mixed types
