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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,74bfb16f8a37fb10 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: operands of membership tests Date: 1997/10/27 Message-ID: #1/1 X-Deja-AN: 285196317 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1997-10-27T00:00:00+00:00 List-Id: Matthew Heaney (mheaney@ni.net) wrote: : A membership never raises Constraint_Error, but evaluation of its operands : might. Suppose I do this : with Ada.Text_IO; use Ada.Text_IO; : procedure Test_Fixed is : type Fixed is delta 1.0 range 0.0 .. 256.0; : for Fixed'Small use 1.0; : begin : Put (Boolean'Image (33_000.0 in Fixed)); : end; : ... : Let's suppose 33_000.0 isn't even in the base range of Fixed. : Can evaluation of the literal 33_000.0 raise Constraint_Error? Not in this case, because Fixed is a static subtype, so the membership test is static (in Ada 95, not Ada 83). On the other hand, if the membership test had not been static, then 33_000.0 would be illegal at compile-time, per RM95 4.9(35). : In RM83 11.6 (9), the note states that an implementation is allowed to : replace the expression with a constant value (in my example, False), even : though the operand is outside the base range of the type. What's the story : in Ada 95? The compiler is required to evaluate a membership test statically in Ada 95 if the operand and the target subtype are both static (see 4.9(11). : What's the more general case, for any relational operator? Under what : circumstances does evaluation of (numeric) literals raise Constraint_Error? : Under what circumstances can an implementation remove an expression it can : evaluate statically, containing (static) operands that are outside the base : range of the type? Evaluation of numeric literals, per se, doesn't raise Constraint_Error. However, they are illegal if outside the base range of the expected type when used in a non-static operation. When used in a static expression, overflow checks are not performed. See RM95 4.9(33-35). : -------------------------------------------------------------------- : Matthew Heaney : Software Development Consultant : : (818) 985-1271 -- -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA