comple_n_runtime_checks.adb

来自「This contains the following topics and m」· ADB 代码 · 共 23 行

ADB
23
字号
--Compile-time and run-time checks
with Text_IO; use Text_IO;
procedure comple_n_runtime_checks is
   type Power_Points is range 0 .. 6;
   type Room_Size is range 0 .. 120;
   subtype Lecture_Room is Room_Size range 0 .. 75;
   subtype Tutorial_Room is Room_Size range 0 .. 20;
   Points_In_504 : Power_Points; --Power outlets
   People_In_504 : Lecture_Room; --Size lecture room
   People_In_616 : Tutorial_Room; --Size tutorial room
begin
   Points_In_504 := 3; --OK
   --Points_In_504 := 80; --compile time Error / Warning --out of range
   People_In_504 := 15; --OK
   People_In_616 := People_In_504; --OK
   --People_In_504 := Points_In_504; -- Type Mismatch subtype cannot eqaute 2
   --type
   -- compile time error
   People_In_504 := Lecture_Room (Points_In_504); --Force
   People_In_504 := 50; --OK
   People_In_616 := People_In_504; --Constraint error -- run time error
end comple_n_runtime_checks;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?