コンテンツにスキップ

出力

waitpid 関数を考えてみましょう。

lib C
  fun waitpid(pid : Int32, status_ptr : Int32*, options : Int32) : Int32
end

関数のドキュメントにはこう書かれています。

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

この関数は以下のように使用できます。

status_ptr = uninitialized Int32

C.waitpid(pid, pointerof(status_ptr), options)

このように、関数に `status_ptr` のポインタを渡して、その値を関数に設定させます。

`out` パラメータを使用することで、上記をより簡単に記述できます。

C.waitpid(pid, out status_ptr, options)

パラメータの型が `Int32*` であるため、コンパイラは自動的に `Int32` 型の `status_ptr` 変数を宣言します。

これは、型がポインタである限り (そしてもちろん、関数がポインタが指す値を設定する限り)、あらゆる `fun` パラメータで機能します。