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,269df2c167555fd6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-02-26 12:22:06 PST Path: supernews.google.com!sn-xit-03!supernews.com!nntp.cs.ubc.ca!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!wn3feed!worldnet.att.net!135.173.83.71!wnfilter1!worldnet-localpost!bgtnsc07-news.ops.worldnet.att.net.POSTED!not-for-mail Message-ID: <3A9ABAF9.F3EABF90@worldnet.att.net> From: James Rogers X-Mailer: Mozilla 4.76 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada 0x: Re: Representation clause References: <3a95c52f@post.usenet.com> <3A95E095.75B2A248@worldnet.att.net> <3a9621eb$1@pull.gecm.com> <3A974A99.469AE413@worldnet.att.net> <87wvagweck.fsf@deneb.enyo.de> <3A97F419.6E2F075@worldnet.att.net> <3tym6.3352$7e6.1360491@homer.alpha.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Mon, 26 Feb 2001 20:20:15 GMT NNTP-Posting-Host: 12.74.128.213 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc07-news.ops.worldnet.att.net 983218815 12.74.128.213 (Mon, 26 Feb 2001 20:20:15 GMT) NNTP-Posting-Date: Mon, 26 Feb 2001 20:20:15 GMT Organization: AT&T Worldnet Xref: supernews.google.com comp.lang.ada:5543 Date: 2001-02-26T20:20:15+00:00 List-Id: Randy Brukardt wrote: > > James Rogers wrote in message <3A97F419.6E2F075@worldnet.att.net>... > >My assertion that Program_Error will be raised is based upon the result > >of tests using GNAT 3.13p. Note that my code does NOT rely on that or > >any other exception being raised to run properly. It detects the > >erroneous condition without causing any exception to be raised. > > Basing it on the RM, rather than a particular compiler, would be better. This is a curious statement. How does the RM solve this problem? Section 13.9 discusses unchecked conversion issues. Section 13.9.1 states that use of Ada.Unchecked_Conversion can result in an invalid representation. 13.9.1 states "It is erroneous to evaluate a primary that is a name denoting an abnormal object, or to evaluate a prefix that denotes an abnormal object. If the representation of a scalar object does not represent a value of the object's subtype, the object is said to have an invalid representation. It is a bounded error to evaluate the value of such an object. If the error is detected, either Constraint_Error or Program_Error is raised. Otherwise, execution continues using the invalid representation." Note that the GNAT 3.13p action of raising Program_Error is fully supported by this clause in the RM. Also note that my code compeletly avoids the creation of invalid data by checking the numeric value against all correct valid internal representations for the enumerated type. This check is done before converting the numeric value to the enumerated type. If the numeric value is not in the set of valid internal representation values for the enumerated type, my code raises its own exception "Out_Of_Range_Error". This is appropriate rather than raising Constraint_Error or Program_Error because no invalid representation is created. > > >It does raise its own exception when an erroneous condition is > >detected. > > > >I admit that I may have generalized the response too much based upon > >testing with one compiler. On the other hand, my solution does not > >rely on that generalization. I therefore feel that my solution is only > >half bad :-). > > Why didn't you use the 'Valid attribute for the check? Then you can can > avoid the erroneous behavior. (Your current code is erroneous if the > representation is out of range, and while it *probably* will work on all > Ada compilers, there is no guarentee of that.) Note that section 13.9 states that data can contain an invalid representation. The code is only erroneous if one attempts to evaluate the data containing an invalid representation. The program is not erroneous if an invalid representation never occurs. I would have to create an invalid representation in order to perform a 'Valid check. Why is this preferred over detecting an out of range source for conversion, and raising an exception to avoid an invalid representation? As has been demonstrated above, it is possible for a compiler to detect the invalid representation and raise either Constraint_Error of Program_Error. What is the value of attempting to use the 'Valid attribute if the compiler will raise an exception before the 'Valid attribute can be checked? Jim Rogers Colorado Springs, Colorado USA