# Printf wrong result passing a float type

**URL:** <https://discourse.julialang.org/t/printf-wrong-result-passing-a-float-type/4688>\
**Category:** New to Julia\
**Tags:** formatting\
**Created:** [July 6, 2017, 1:24pm UTC](https://discourse.julialang.org/t/printf-wrong-result-passing-a-float-type/4688 "2017-07-06T13:24:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlxG78](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@AlxG78](https://discourse.julialang.org/u/AlxG78)\
**Post date:** [July 6, 2017, 1:24pm UTC](https://discourse.julialang.org/t/printf-wrong-result-passing-a-float-type/4688/1 "2017-07-06T13:24:30Z")

</div>

Julia 0.6, because this result, what am I doing wrong?

```julia
julia> ccall(:printf, Cint, (Ptr{UInt8}, Cfloat), "%f\n", 2.5);
0.000000

```

---

<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:** [July 6, 2017, 1:37pm UTC](https://discourse.julialang.org/t/printf-wrong-result-passing-a-float-type/4688/2 "2017-07-06T13:37:53Z")

</div>

Variadic functions in C are weird, they may not have the same calling convention as normal arguments. In particular, you need to use `Cdouble` due to [default convertions](http://en.cppreference.com/w/cpp/language/variadic_arguments#Default_conversions) in this case.

```julia
julia> ccall(:printf, Cint, (Cstring, Cdouble), "%f\n", 2.5);
2.500000

```

---

<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:** [July 6, 2017, 2:01pm UTC](https://discourse.julialang.org/t/printf-wrong-result-passing-a-float-type/4688/3 "2017-07-06T14:01:39Z")

</div>

Also note that there’s still a calling convention mismatch in this case and the correct way is

```julia
ccall(:printf, Cint, (Cstring, Cdouble...), "%f\n", 2.5)

```

The uninitialized register value in `rax` seems to have the same effect in this case though…  
We currently don’t have a good [syntax for calling variadic functions with different types](https://docs.julialang.org/en/latest/manual/calling-c-and-fortran-code/)
