Created
July 30, 2014 14:43
-
-
Save ytomino/91a5c77e7c9316e2aee3 to your computer and use it in GitHub Desktop.
コンパイル時に結果をチェックできる引き算
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package dtmodoki is | |
-- minus functions ensuring Left >= Right (Left - Right >= 0) | |
generic | |
X : Natural; | |
Y : Natural; | |
package Natural_Minus is | |
subtype Result is Natural range X - Y .. X - Y; | |
function F return Result is (X - Y); | |
end Natural_Minus; | |
package Calc_5_Minus_3 is new Natural_Minus (5, 3); -- OK | |
package Calc_3_Minus_5 is new Natural_Minus (3, 5); -- warned | |
--dtmodoki.ads:19:04: warning: in instantiation at line 9 | |
--dtmodoki.ads:19:04: warning: static value out of range of type "Standard.Natural" | |
--dtmodoki.ads:19:04: warning: "Constraint_Error" will be raised at run time | |
end dtmodoki; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment