# Precompilation problem setting const Ref{Ptr} in a Module

**URL:** https://discourse.julialang.org/t/precompilation-problem-setting-const-ref-ptr-in-a-module/19988
**Category:** General Usage
**Tags:** question, package, module, precompilation
**Created:** [January 23, 2019, 2:46pm UTC](https://discourse.julialang.org/t/precompilation-problem-setting-const-ref-ptr-in-a-module/19988 "2019-01-23T14:46:55Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![PhilipV](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/philipv/32/6852_2.png) [@PhilipV](https://discourse.julialang.org/u/PhilipV)
#### Post date: [January 23, 2019, 2:46pm UTC](https://discourse.julialang.org/t/precompilation-problem-setting-const-ref-ptr-in-a-module/19988/1 "2019-01-23T14:46:56Z")

</div>

Hi everyone,

I’m working on a [PR](https://github.com/JuliaParallel/MPI.jl/pull/232) to extend MPI.jl, which is a Julia package ccalling into a C/Fortran library.

I need to store inside my module a constant `Ref{Ptr{Cvoid}}`. Since the precompiler actually clears the value of all pointers, I learned that I must do it in the ` __init__ ` method of my Module.

Unfortunately, this does not seem to work unless I use an `eval` call, which breaks incremental compilation, and as such I want to avoid it.

For example, consider the following package:

```julia
bash> mkdir -p MyModule/src && echo "
module MyModule
 const a = Ref{Ptr{Cvoid}}()
 const b = Ref{Ptr{Cvoid}}()

 function __init__ ()
     a[] = Ptr{Cvoid}(1)
     eval(:(b[] = 1))
 end
end" >> MyModule/src/MyModule.jl && cd MyModule

```

then, if you dev it and `using` it (which is necessary to trigger a precompilation), you will see that `a` has been reset:

```julia
julia> ] dev .
julia> using MyModule
julia> MyModule.a
Base.RefValue{Ptr{Nothing}}(Ptr{Nothing} @0x0000000000000000)
julia> MyModule.b
Base.RefValue{Ptr{Nothing}}(Ptr{Nothing} @0x0000000000000001)

```

How can I set this variable without using an `eval` call?

–

---

<div class="post-metadata">

### Author: ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)
#### Post date: [January 24, 2019, 1:30am UTC](https://discourse.julialang.org/t/precompilation-problem-setting-const-ref-ptr-in-a-module/19988/2 "2019-01-24T01:30:06Z")

</div>

Just don’t use constants and call them pointers—either use runtime values or call them integers. It’s probably quite bad that we’re rewriting even the source code constant 1 into a null pointer, but that’s usually not observed in practice
