跳轉到內容

Ada 程式設計/屬性

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

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

當宣告變數或子程式等實體時,其某些屬性通常由編譯器指定(例如變數的大小或地址、子程式的呼叫約定)。可以查詢的屬性稱為 *屬性*;可以指定的屬性稱為 方面。方面和屬性在 Ada 參考手冊的附件中定義 附件 K:語言定義的方面和屬性 [帶註釋的].

語言摘要屬性

[編輯 | 編輯原始碼]

*屬性* 的概念對於 Ada 來說非常獨特。屬性允許您獲取 - 並且有時設定 - 關於物件或其他語言實體(如型別)的資訊。一個很好的例子是 Size 屬性。它描述了物件或型別的大小(以位為單位)。

A : Natural := Integer'Size; -- A is now 32 (with the GNAT compiler for the x86 architecture)

但是,與來自 C/C++sizeof 運算子不同,Size 屬性也可以設定。

type Byte is range -128 .. 127;  -- The range fits into 8 bits but the
                                 -- compiler is still free to choose.
for  Byte'Size use 8;            -- Now we force the compiler to use 8 bits.

當然,並非所有屬性都可以設定。屬性以一個 '(撇號)開頭,後跟屬性名稱。編譯器透過上下文確定撇號是屬性的開始,還是字元文字或量化表示式的開始。

A : Character := Character'Val (32);     -- A is now a space
B : Character := ' ';                    -- B is also a space
S : String    := Character'(')')'Image;  -- an especially nice parsing exercise

語言定義屬性列表

[編輯 | 編輯原始碼]
Ada 2005
這是一個新的 Ada 2005 屬性。
Ada 2012
這是一個新的 Ada 2012 屬性。
Ada 2022
這是一個新的 Ada 2022 屬性。
過時
這是一個已棄用的屬性,不應在新的程式碼中使用。

實現定義屬性列表

[編輯 | 編輯原始碼]

以下屬性並非所有 Ada 編譯器都提供,僅在實現過這些屬性的編譯器中提供。

目前,只列出了幾個編譯器的實現定義屬性。您可以幫助 Wikibooks 新增 其他編譯器的特定屬性。

GNAT
實現定義屬性 來自 AdaCore/FSF 的 GNAT 編譯器。
HP Ada
HP Ada 編譯器(以前稱為“DEC Ada”)的實現定義屬性。
ICC
Irvine ICC 編譯器的實現定義屬性[1]
PowerAda
實現定義屬性 來自 OC Systems 的 PowerAda
SPARCompiler
實現定義屬性 來自 Sun 的 SPARCompiler Ada。

O – T

[edit | edit source]

U – Z

[edit | edit source]

另請參閱

[edit | edit source]

華夏公益教科書

[edit | edit source]

Ada 語言參考手冊

[edit | edit source]

Ada 83

[edit | edit source]

Ada 95

[edit | edit source]

Ada 2005

[edit | edit source]

Ada 2012

[edit | edit source]

Ada 2022

[edit | edit source]

參考文獻

[edit | edit source]
  1. "4.2 ICC-Defined Attributes", ICC Ada Implementation Reference — ICC Ada Version 8.2.5 for i960MC Targets, document version 2.11.4 [1]
華夏公益教科書