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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9e499c74312ed3f0 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-05-18 16:03:47 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.skycache.com!Cidera!news-reader.ntrnet.net!uunet!ash.uu.net!xyzzy!nntp From: Jeffrey Carter Subject: Re: Static assertions X-Nntp-Posting-Host: e246420.msc.az.boeing.com Content-Type: text/plain; charset=us-ascii Message-ID: <3B05A63C.25F6B80C@boeing.com> Sender: nntp@news.boeing.com (Boeing NNTP News Access) Content-Transfer-Encoding: 7bit Organization: The Boeing Company X-Accept-Language: en References: <3B054ABE.9B3DA459@boeing.com> Mime-Version: 1.0 Date: Fri, 18 May 2001 22:46:20 GMT X-Mailer: Mozilla 4.5 [en]C-CCK-MCD Boeing Kit (WinNT; U) Xref: archiver1.google.com comp.lang.ada:7644 Date: 2001-05-18T22:46:20+00:00 List-Id: Robert A Duff wrote: > > Jeffrey Carter writes: > > > However, is there any reason to write > > > > Assert_1 : constant := Boolean'Pos (Assert'(Integer'Size = 73) ); > > > > rather than > > > > Assert_1 : constant Assert := Integer'Size = 73; > > > > ? Are there compilers that won't check this during compilation? > > I think the former is required to get a compile time error, > whereas the latter is merely allowed to produce a warning. > The subtle difference is that the former has a static expression > raising an exception, whereas the latter has a perfectly good > static expression, but the assignment will raise an exception. > I'm too lazy to look it up in the RM, so I could be mistaken... > > Furthermore, if the second one doesn't get detected at compile time, it > might not get detected at all. I believe 11.6 allows the compiler to > "optimize away" the constraint check, so it never happens at run time. > (I'm assuming Assert_1 is a dead variable.) I see. Assert_1 cannot be a dead variable, since it is a constant, but it will probably never be referenced. I guess it's a "dead constant". It would appear that Assert_1 : constant Assert := Assert'(Integer'Size = 73); must cause a compilation error, since Assert is a static subtype, so the qualified expression is static, and a static qualified expression must be evaluated at compile time. I'm just trying to come up with something a little shorter and less obscure than using Boolean'Pos. -- Jeffrey Carter