Documentation on Ref in 0.4?

269 views
Skip to first unread message

Douglas Bates

unread,
May 7, 2015, 1:42:06 PM5/7/15
to juli...@googlegroups.com
I have read through the "Calling C and Fortran ..." section of the 0.4 documentation and issue #2818 but I am still a bit confused about the use of Ref{T} versus Ptr{T} in argument signatures in ccall and in type signatures in type declarations.

Is there more discussion of Ref that I could look at or are there particular packages that show its use?

Jacob Quinn

unread,
May 7, 2015, 2:33:05 PM5/7/15
to juli...@googlegroups.com
My understanding is that before, to do things like pass a *int or *char, you allocated an Array(Int32,1) or Array(Char,1) and passed Ptr{Int} or Ptr{Char}. With Ref, you can just pass Ref{Int}() or Ref{Char}() which will create the necessary box to pass. I have some unpublished code that uses Ref{Char}() for reading a single character from a file stream. I can share if you'd like.

-Jacob

wil...@gmail.com

unread,
May 8, 2015, 11:13:17 AM5/8/15
to juli...@googlegroups.com, quinn....@gmail.com
My question: How do you dereference something from Ref object?

I have a `void **objs` argument in a C function. The function creates an object reference and reference to it in objs.

   void foo(void **objs)

In Julia I call this function as follows:

    obj_ptr_ptr = Ref{Ptr{Void}}(C_NULL)
    ccall((:foo, :libfoo), Void, (Ptr{Ptr{Void}},), obj_ptr_ptr)

How do I get back the referenced object that was created in foo(). There is only `getindex` function for the `Ref` type which gives:

    obj_ptr = obj_ptr_ptr[]

Wouldn't it be nice to have some unary operator for dereference?

-- Art

Steven G. Johnson

unread,
May 15, 2015, 5:20:06 PM5/15/15
to juli...@googlegroups.com, quinn....@gmail.com


On Friday, May 8, 2015 at 11:13:17 AM UTC-4, wil...@gmail.com wrote:
My question: How do you dereference something from Ref object?


Wouldn't it be nice to have some unary operator for dereference?

Isn't [] just a unary postfix operator that happens to use two characters?


Reply all
Reply to author
Forward
0 new messages