From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,XPRIO autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9e499c74312ed3f0,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-05-17 08:10:03 PST Path: archiver1.sj.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!oleane.net!oleane!nnrp.oleane.net!not-for-mail From: "Jean-Pierre Rosen" Newsgroups: comp.lang.ada Subject: Static assertions Date: Thu, 17 May 2001 17:07:51 +0200 Organization: Adalog Message-ID: <9e0pfb$ao9$1@s1.read.news.oleane.net> NNTP-Posting-Host: mailhost.axlog.fr X-Trace: s1.read.news.oleane.net 990112043 11017 195.25.228.57 (17 May 2001 15:07:23 GMT) X-Complaints-To: abuse@oleane.net NNTP-Posting-Date: Thu, 17 May 2001 15:07:23 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Xref: archiver1.sj.google.com comp.lang.ada:7615 Date: 2001-05-17T17:07:51+02:00 List-Id: Still discovering how powerful Ada is... Imagine your program relies on Integer having a certain size, or being sure that the size of Integer is four times the size of character, or things like that, and you want to make sure that the program does not even compile if the assertions do not hold (because you hate fighting with a debugger). This is possible, since a static expression that raises constraint_error will not compile. Just include something like the following package: package Verifier is subtype Assert is Boolean range True..True; Assert_1 : constant := Boolean'Pos( Assert (Integer'Size=32) ); Assert_2 : constant := Boolean'Pos( Assert (Integer'Size=4*Character'Size) ); end Verifier; (The Boolean'Pos serves to have a value used in a named number declaration, which requires a static context). -- --------------------------------------------------------- J-P. Rosen (rosen@adalog.fr) Visit Adalog's web site at http://www.adalog.fr