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,751584f55705ddb7 X-Google-Attributes: gid103376,public From: stt@henning.camb.inmet.com (Tucker Taft) Subject: Re: Side-effect arithmetic again [was: Ada ... in embedded systems] Date: 1996/03/28 Message-ID: #1/1 X-Deja-AN: 144685102 sender: news@inmet.camb.inmet.com (USENET news) x-nntp-posting-host: henning.camb.inmet.com references: <4jcgk6$eeo@dayuc.dayton.saic.com> organization: Intermetrics, Inc. newsgroups: comp.lang.ada Date: 1996-03-28T00:00:00+00:00 List-Id: John G. Volan (John_Volan@ccmail.dayton.saic.com) wrote: : In article Robert Dewar, dewar@cs.nyu.edu writes: : >John Volan said : > : >> procedure Increment (This : in out Item; By: in Positive) is : >> begin : >> This := Item'Val(Item'Pos(This) + By); : >> end Increment; : > : >is that it doesn't just limit the "By" parameter to Standard.Positive, : >it also limits the "This" parameter to possibly a relatively small : >range of the Item type." : > : >Well I can't get particularly upset by that , but if you are, just : >change this to Item'Val (Item'Pos(This) + Positive'Pos (By)). : Okay, that leaves the exact type returned by the 'Pos functions : ambiguous, but what does Ada95 do in that case? Does it just default : to Standard.Integer anyway? (In that case, your answer doesn't really : solve the problem.) Or can the compiler pick an integer type that's big : enough? Or does this simply cause a compilation error? The 'Pos attribute returns a value of type universal_integer, which is implicitly convertible to any integer type. Given that you are adding it to a value of subtype Positive, it will be converted to Integer (since Positive is a subtype of Integer). See RM95 3.5.5(4), 8.6(24), 6.4.1(11). : ( Name => "John G. Volan", E_Mail => "John_Volan@dayton.saic.com", -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Cambridge, MA USA