# Unsigned long in ccall

**URL:** https://discourse.julialang.org/t/unsigned-long-in-ccall/38557
**Category:** General Usage
**Tags:** interoperability
**Created:** [May 1, 2020, 1:54pm UTC](https://discourse.julialang.org/t/unsigned-long-in-ccall/38557 "2020-05-01T13:54:23Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)
#### Post date: [May 1, 2020, 1:54pm UTC](https://discourse.julialang.org/t/unsigned-long-in-ccall/38557/1 "2020-05-01T13:54:23Z")

</div>

I need to call a MPFR library function whose signature is `int mpfr_sub_ui(mpfr_t rop, mpfr_t op1, unsigned long int op2, mpfr_rnd_t rnd)`.

The [manual](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/#mapping-c-types-to-julia-1) says that `unsigned long` is an Int on Unix and an Int32 on Windows. Is there a way to `ccall` the library function that works on both Unix and Windows?

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [May 1, 2020, 2:13pm UTC](https://discourse.julialang.org/t/unsigned-long-in-ccall/38557/2 "2020-05-01T14:13:50Z")

</div>

`Culong` should do the right thing:

```julia
julia> Culong
UInt64

```

---

<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: [May 1, 2020, 2:13pm UTC](https://discourse.julialang.org/t/unsigned-long-in-ccall/38557/3 "2020-05-01T14:13:54Z")

</div>

`Culong`

---

<div class="post-metadata">

### Author: ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)
#### Post date: [May 1, 2020, 2:14pm UTC](https://discourse.julialang.org/t/unsigned-long-in-ccall/38557/4 "2020-05-01T14:14:31Z")

</div>

> [@mzaffalon](#):
>
> The [manual](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/#mapping-c-types-to-julia-1) says that `unsigned long` is an Int on Unix and an Int32 on Windows.

But the manual says:

> **System Dependent Types**
> 
> | C name | Standard Julia Alias | Julia Base Type |
> | --- | --- | --- |
> | `char` | `Cchar` | `Int8` (x86, x86\_64), `UInt8` (powerpc, arm) |
> | `long` | `Clong` | `Int` (UNIX), `Int32` (Windows) |
> | `unsigned long` | `Culong` | `UInt` (UNIX), `UInt32` (Windows) |
> | `wchar_t` | `Cwchar_t` | `Int32` (UNIX), `UInt16` (Windows) |

---

<div class="post-metadata">

### Author: ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)
#### Post date: [May 1, 2020, 2:23pm UTC](https://discourse.julialang.org/t/unsigned-long-in-ccall/38557/5 "2020-05-01T14:23:36Z")

</div>

The library has also function `mpfr_sub_si` with signature `long int`. What I should have asked is how should the Julia wrappers be defined.

```julia
function mpfr_sub(rop::BigFloat, op1::BigFloat, op2::UInt, rnd) # for unsigned long int
    ccall((:mpfr_sub_ui, :libmpfr), Int32,
              (Ref{BigFloat}, Ref{BigFloat}, Culong, MPFR.MPFRRoundingMode),
              rop, op1, op2, rnd)
 end

```

and

```julia
function mpfr_sub(rop::BigFloat, op1::BigFloat, op2::Int, rnd) # for long int
    ccall((:mpfr_sub_si, :libmpfr), Int32,
              (Ref{BigFloat}, Ref{BigFloat}, Clong, MPFR.MPFRRoundingMode),
              rop, op1, op2, rnd)
end

```

---

<div class="post-metadata">

### Author: ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)
#### Post date: [May 1, 2020, 2:45pm UTC](https://discourse.julialang.org/t/unsigned-long-in-ccall/38557/6 "2020-05-01T14:45:00Z")

</div>

Julia’s `MPFR` module in `Base` uses `ClongMax` and `CulongMax` defined in `GMP`:

```julia
julia> Base.GMP.CulongMax
Union{UInt16, UInt32, UInt8}

julia> Base.GMP.ClongMax
Union{Int16, Int32, Int8}

```

---

<div class="post-metadata">

### Author: ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)
#### Post date: [May 1, 2020, 2:46pm UTC](https://discourse.julialang.org/t/unsigned-long-in-ccall/38557/7 "2020-05-01T14:46:16Z")

</div>

Because you are on a Unix-like system? On Windows, I get:

```julia
julia> Culong
UInt32

```
