跳轉到內容

Ada 程式設計/編譯指示/限制

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

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

Restrictions 編譯指示用於禁止使用某些語言特性。

語言定義的限制識別符號列表

[編輯 | 編輯原始碼]

一些限制具有特殊標記

Ada 2005
這是新的 Ada 2005 限制識別符號。
Ada 2012
這是新的 Ada 2012 限制識別符號。

實現定義的限制識別符號列表

[編輯 | 編輯原始碼]

以下限制並非所有 Ada 編譯器都支援,僅在那些已經實現它們的編譯器中可用

GNAT
這是一個 實現定義的限制識別符號,屬於 GNAT 編譯器。

"Hello, world!" with restrictions

[編輯 | 編輯原始碼]

以下示例演示了pragma Restrictions的使用。請注意,在 Windows、Linux 和 macOS 上,給定的限制不會更改生成的程式碼。

檔案: hello_world_restricted.adb, Crate: pragmas_restrictions (檢視, 純文字, 使用 Alire 下載, Alire crate 資訊)

程式碼:

pragma Restrictions (
   Simple_Barriers,
   No_Abort_Statements,
   No_Asynchronous_Control,
   No_Calendar,
   No_Delay,
   No_Dynamic_Attachment,
   No_Dynamic_Priorities,
   No_Enumeration_Maps,
   No_Entry_Calls_In_Elaboration_Code,
   No_Entry_Queue,
   No_Exception_Registration,
   No_Initialize_Scalars,
   No_Local_Protected_Objects,
   No_Protected_Type_Allocators,
   No_Protected_Types,
   No_Relative_Delay,
   No_Requeue_Statements,
   No_Select_Statements,
   No_Streams,
   No_Task_Allocators,
   No_Task_Attributes_Package,
   No_Task_Hierarchy,
   No_Task_Termination,
   No_Tasking,
   No_Terminate_Alternatives,
   No_Wide_Characters,
   Static_Priorities,
   Static_Storage_Size,
   Immediate_Reclamation,
   No_Implementation_Restrictions,
   Max_Protected_Entries => 0,
   Max_Protected_Entries => 0,
   Max_Select_Alternatives => 0,
   Max_Task_Entries => 0,
   Max_Tasks => 0,
   Max_Asynchronous_Select_Nesting => 0);

with Ada.Text_IO;

procedure Hello_World_Restricted is
begin
   Ada.Text_IO.Put_Line ("Hello World!");
   Ada.Text_IO.New_Line;
   Ada.Text_IO.Put_Line ("This is a program with restricted runtime.");
end Hello_World_Restricted;

輸出:

>alr run hello_world_restricted
ⓘ Building pragmas_restrictions=1.0.1/pragmas_restrictions.gpr...          
Compile
   [Ada]          hello_world_restricted.adb
Bind
   [gprbind]      hello_world_restricted.bexch
   [Ada]          hello_world_restricted.ali
Link
   [link]         hello_world_restricted.adb
✓ Build finished successfully in 0.83 seconds.
Hello World!

This is a program with restricted runtime.

華夏公益教科書

[編輯 | 編輯原始碼]

Ada 參考手冊

[編輯 | 編輯原始碼]

Ada 質量和風格指南

[編輯 | 編輯原始碼]
華夏公益教科書