跳轉到內容

Ada 程式設計/關鍵字/use

來自華夏公益教科書,自由的教科書

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

Use 子句

[編輯 | 編輯原始碼]

Use 子句有兩種版本:use_package_clause 和 use_type_clause。

在庫級別

[編輯 | 編輯原始碼]

此 use_package_clause 使 的內容直接可見。如果應用在庫級別,它的作用範圍是整個庫單元。

Use 子句不會隱藏任何原本無需它就能直接可見的內容。在某個範圍內生效的所有 use 子句都處於同一級別:來自不同包的兩個同音異義詞仍然必須作為選定元件進行命名。

with Ada.Text_IO;   use Ada.Text_IO;

procedure Hello is
begin
   Put_Line("Hello, world!");
   New_Line;
   Put_Line("I am an Ada program with package use.");
end Hello;

如果可讀性是你的主要關注點,那麼你應該避免使用這種 use 子句。要麼使它更區域性化,要麼使用 use_type_clause。

在宣告級別

[編輯 | 編輯原始碼]

效果與上面相同,但作用範圍是直接包含的宣告區域。

檔案:hello_world_3.adb (檢視, 純文字, 下載頁面, 瀏覽所有)
with Ada.Text_IO;

procedure Hello is
   use Ada.Text_IO;
begin
   Put_Line("Hello, world!");
   New_Line;
   Put_Line("I am an Ada program with package use.");
end Hello;

對於型別

[編輯 | 編輯原始碼]

Use 型別子句有兩種版本。

use type Type_Name;

使型別的運算子直接可見。

use all type Type_Name;

使型別的基本操作直接可見。

表示子句

[編輯 | 編輯原始碼]

關鍵字for, useat 用於表示子句。

記錄表示子句指定記錄的 佈局 方面

列舉表示子句指定列舉型別的 編碼 方面

參見 Ada 程式設計/表示子句

華夏公益教科書

[編輯 | 編輯原始碼]

Ada 參考手冊

[編輯 | 編輯原始碼]

Ada 質量和風格指南

[編輯 | 編輯原始碼]


Ada 關鍵字
abort else new return
abs elsif not reverse
abstract (Ada 95) end null
accept entry select
access exception of separate
aliased (Ada 95) exit or some (Ada 2012)
all others subtype
and for out synchronized (Ada 2005)
array function overriding (Ada 2005)
at tagged (Ada 95)
generic package task
begin goto parallel (Ada 2022) terminate
body pragma then
if private type
case in procedure
constant interface (Ada 2005) protected (Ada 95) until (Ada 95)
is use
declare raise
delay limited range when
delta loop record while
digits rem with
do mod renames
requeue (Ada 95) xor
華夏公益教科書