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 14:29:20 PST Newsgroups: comp.lang.ada Path: archiver1.sj.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!world!bobduff From: Robert A Duff Subject: Re: Static assertions Sender: bobduff@world.std.com (Robert A Duff) Message-ID: Date: Fri, 18 May 2001 21:27:24 GMT References: <3B054ABE.9B3DA459@boeing.com> Organization: The World Public Access UNIX, Brookline, MA X-Newsreader: Gnus v5.3/Emacs 19.34 Xref: archiver1.sj.google.com comp.lang.ada:7640 Date: 2001-05-18T21:27:24+00:00 List-Id: Jeffrey Carter writes: > Isn't that "Danger, Will Robinson"? Probably. > I certainly agree with this advice. One thing that always stopped me > short in my tracks was code with constructs such > > ... + My_Type (3) - ... > > apparently written by people who thought that "3" has type Integer (or > perhaps used a compiler with that "feature"). Well, there *are* languages where "3" is an int, and "3L" is a long (or even "3l"). Yuck. > 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.) - Bob