ウィキのコピーミラー

これは pascal.chat のウィキのミラーです。編集、履歴、ログインはそちらで行います。

Basic Pascal Tutorial/Chapter 4/Forward Referencing/ja

4F - 前方参照 (著者: Tao Yue, 状態: 原文のまま変更なし)

難しいトピックが続いたが、ここでは簡単なことを話そう。

手続きや関数はすでに定義済みの変数やサブプログラムだけを見ることができたことを思いだそう。だが、ひとつ例外がある。

お互いが他方を呼び出している2つのサブプログラムがあるとすると、どちらを最初に置くべきかというジレンマが生じる。もう一方は最初のものからまだ呼び出せないからである。

この「卵が先か鶏が先か」問題をとくためには 前方参照 を使う。

pascal
procedure Later (parameter list); forward;
    
    procedure Sooner (parameter list);
    begin
      ...
      Later (parameter list);
    end;
    ...
    procedure Later;
    begin
      ...
      Sooner (parameter list);
    end;

関数も同様である。単にヘッディングの終わりに forward をつければ良い。

previous contents next

From the Free Pascal wiki, page "Forward Referencing/ja", as the Internet Archive kept it on 2023-03-30, last changed on 2022-08-20. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

第2版、最終更新:WikiArchive 。