跳到內容

Ada 程式設計/方面/無返回值

來自華夏公益教科書,開放的書籍,開放的世界

Ada. Time-tested, safe and secure.
Ada.經久考驗,安全可靠。
with No_Return

指定 No_Return 方面表示過程不能正常返回;它可能會引發異常,迴圈永遠執行,或終止程式。

非返回過程不能包含任何返回語句。如果非返回過程隱式返回(透過到達其語句序列的末尾),則Program_Error將在呼叫點引發。

在呼叫點,這可以檢測死程式碼並抑制關於缺少返回語句或缺少對變數賦值的警告。

procedure P ( … ) with No_Return;
procedure Q (x : out … ) is
begin
  if Cond then
    P ( … );
    Some_Thing_Else; -- This is dead code--and due to No_Return probably a compiler warning!
  else
    x := … ;
  end if;
  -- No warning about a missing assignment to x here
end Q;

可移植性

[編輯 | 編輯原始碼]

No_Return 方面是在 Ada 2012 中引入的。它是[1]對 Ada 2005 中引入的 No_Return [Annotated] [Annotated] 的替代。[Annotated]

華夏公益教科書

[編輯 | 編輯原始碼]

Ada 參考手冊

[編輯 | 編輯原始碼]

參考文獻

[編輯 | 編輯原始碼]
  1. AI05-0229
  2. AI95-00329
華夏公益教科書