# Macro that uses ccall in julia-0.6.0

**URL:** <https://discourse.julialang.org/t/macro-that-uses-ccall-in-julia-0-6-0/2639>\
**Category:** General Usage\
**Created:** [March 13, 2017, 3:01pm UTC](https://discourse.julialang.org/t/macro-that-uses-ccall-in-julia-0-6-0/2639 "2017-03-13T15:01:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)\
**Post date:** [March 13, 2017, 3:01pm UTC](https://discourse.julialang.org/t/macro-that-uses-ccall-in-julia-0-6-0/2639/1 "2017-03-13T15:01:56Z")

</div>

I have the following macro:

```julia
macro xprs_ccall(func, args...)

    f = "XPRS$(func)"
    args = map(esc,args)

    is_unix() && return quote
        ccall(($f,xprs), $(args...))
    end
    is_windows() && return quote
        ccall(($f,xprs), stdcall, $(args...))
    end
end

```

where `xprs` is a const previously defined.

when I try:  
`@xprs_ccall(getversion, Cint, ( Ptr{Cchar}, ) , out)`  
I get:  
`ERROR: syntax: ccall argument types must be a tuple; try "(T,)"`

I tested:

```julia
julia> macroexpand( :(@xprs_ccall(getversion, Cint, ( Ptr{Cchar}, ) , out)))
quote # REPL[5], line 10:
    ccall(("XPRSgetversion", Main.xprs), Main.stdcall, Cint, (Ptr{Cchar},), out)

end

```

It seems to be a tuple…

When I remove the word stdcall from the macro:

```julia
macro xprs_ccall(func, args...)

    f = "XPRS$(func)"
    args = map(esc,args)

    is_unix() && return quote
        ccall(($f,xprs), $(args...))
    end
    is_windows() && return quote
        ccall(($f,xprs), $(args...))
    end
end

```

Everything works just fine.

Any Ideas why?

---

<div class="post-metadata">

**Author:** ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)\
**Post date:** [March 13, 2017, 3:10pm UTC](https://discourse.julialang.org/t/macro-that-uses-ccall-in-julia-0-6-0/2639/2 "2017-03-13T15:10:49Z")

</div>

Actually, both work:  
`ccall((:XPRSgetversion, xprs), Cint, ( Ptr{Cchar}, ) , out)`

`ccall((:XPRSgetversion, xprs), stdcall, Cint, ( Ptr{Cchar}, ) , out)`

So it is something in that macro…

---

<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:** [March 13, 2017, 3:14pm UTC](https://discourse.julialang.org/t/macro-that-uses-ccall-in-julia-0-6-0/2639/3 "2017-03-13T15:14:35Z")

</div>

As shown in your macro expansion result, you need to escape the `stdcall`.

---

<div class="post-metadata">

**Author:** ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)\
**Post date:** [March 13, 2017, 8:17pm UTC](https://discourse.julialang.org/t/macro-that-uses-ccall-in-julia-0-6-0/2639/4 "2017-03-13T20:17:39Z")

</div>

Is this what you mean?

```julia
macro xprs_ccall(func, args...)

    f = "XPRS$(func)"
    args = map(esc,args)

    is_unix() && return quote
        ccall(($f,xprs), $(args...))
    end
    is_windows() && return quote
        ccall(($f,xprs), esc(stdcall), $(args...))
    end
end

```

Because it returns the same error…

---

<div class="post-metadata">

**Author:** ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)\
**Post date:** [March 13, 2017, 8:21pm UTC](https://discourse.julialang.org/t/macro-that-uses-ccall-in-julia-0-6-0/2639/5 "2017-03-13T20:21:12Z")

</div>

This works:

```julia
macro xprs_ccall(func, args...)
    f = "XPRS$(func)"
    args = map(esc,args)

    is_unix() && return quote
        ccall(($f,xprs), $(args...))
    end
    is_windows() && return quote
        ccall(($f,xprs), $(esc(:stdcall)), $(args...))
    end
end

```

thanks!

---

<div class="post-metadata">

**Author:** ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)\
**Post date:** [March 14, 2017, 9:36pm UTC](https://discourse.julialang.org/t/macro-that-uses-ccall-in-julia-0-6-0/2639/6 "2017-03-14T21:36:14Z")

</div>

This last example does not work properly on julia-0.5.0 (and 0.5.1), it returns:

```julia
ERROR: syntax: ccall argument types must be a tuple; try "(T,)"

```
