out

Consider the waitpid function:

  1. lib C
  2. fun waitpid(pid : Int32, status_ptr : Int32*, options : Int32) : Int32
  3. end

The documentation of the function says:

  1. The status information from the child process is stored in the object
  2. that status_ptr points to, unless status_ptr is a null pointer.

We can use this function like this:

  1. status_ptr = uninitialized Int32
  2. C.waitpid(pid, pointerof(status_ptr), options)

In this way we pass a pointer of status_ptr to the function for it to fill its value.

There’s a simpler way to write the above by using an out parameter:

  1. C.waitpid(pid, out status_ptr, options)

The compiler will automatically declare a status_ptr variable of type Int32, because the parameter’s type is Int32*.

This will work for any fun parameter, as long as its type is a pointer (and, of course, as long as the function does fill the value the pointer is pointing to).