# Why isn't \`pointer(Cint(0))\` valid?

**URL:** <https://discourse.julialang.org/t/why-isnt-pointer-cint-0-valid/7654>\
**Category:** General Usage\
**Created:** [December 9, 2017, 3:15pm UTC](https://discourse.julialang.org/t/why-isnt-pointer-cint-0-valid/7654 "2017-12-09T15:15:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![standarddeviant](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/standarddeviant/32/2309_2.png) [@standarddeviant](https://discourse.julialang.org/u/standarddeviant)\
**Post date:** [December 9, 2017, 3:15pm UTC](https://discourse.julialang.org/t/why-isnt-pointer-cint-0-valid/7654/1 "2017-12-09T15:15:41Z")

</div>

I’m trying to wrap a library with `ccall`. The following yields an error:

```julia
a = Cint(0)
p = pointer(a)

```

But this works and I think does what I want:

```julia
a = Vector{Cint}(1); a[1]=0;
p = pointer(a)

```

But it feels awfully silly to have to do this. To pass a pointer to a `Cint`, is the latter the correct way to pass a `Ptr{Cint}` to a C function? Is there a good reason for not allowing `pointer(Cint(0))` ?

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [December 9, 2017, 3:41pm UTC](https://discourse.julialang.org/t/why-isnt-pointer-cint-0-valid/7654/2 "2017-12-09T15:41:12Z")

</div>

Use:

```julia
a = Ref{Cint}(0)
ccall((:func, :lib), Void, (Ptr{Cint},), a)

```

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [December 9, 2017, 6:01pm UTC](https://discourse.julialang.org/t/why-isnt-pointer-cint-0-valid/7654/3 "2017-12-09T18:01:21Z")

</div>

Simon answered your first question; here’s a shot at the second

> [@standarddeviant](#):
>
> Is there a good reason for not allowing pointer(Cint(0)) ?

The statement `a=Cint(0)` just binds the symbol `:a` to an object of scalar bits type, which is immutable - i.e. managed by copying. There is no guarantee that it is ever even associated with a memory location, and it would encumber the compiler too much to allow user code to force such an association. (So it’s similar to a strictly enforced `register` storage class in C.)
