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,83d7c4caadb45100 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: DECAda/VMS - calling GETJPI Date: 1996/06/05 Message-ID: #1/1 X-Deja-AN: 158612603 references: <31B2AF74.668E@dial.eunet.ch> <4p1v56$214@linus.mitre.org> <4p32m3$51g@mulga.cs.mu.OZ.AU> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-06-05T00:00:00+00:00 List-Id: In article <4p32m3$51g@mulga.cs.mu.OZ.AU>, Fergus Henderson wrote: >It would be helpful if someone were to give a brief explanation >of the arguments in favour of this design decision. I can't remember all the details of the arguments at the time. I think part of it was that people thought the old rules were confusing. People felt that since -1 is simply not a value of the modular type, that it ought to raise C_E on conversion. Arithmetic purely within the modular type is different -- you can never get the value -1 in the first place. One might like type conversions to be reversible. I: Integer := -1; subtype S1 is Integer range 0..255; X: S1 := 255; subtype S2 is Integer range -128..127; Y: S2 := -1; type M is mod 256; Z: M; Now converting 255 of type M to type Integer produces 255, clearly, and not -1. So: Z := M(I); -- Contraint_Error happens here, but if it didn't, then I := Integer(Z); -- ...now I has changed its value, which some -- might consider strange. Z := M(Y); -- OK. X := Integer(Z); -- Here, X has the same value it did before. Z := M(X); -- Contraint_Error happens here, but if it didn't, then Y := Integer(Z); -- ...you'd get Constraint_Error here. Whether this would confuse is, I suppose, a matter of opinion. Now, consider: procedure P(Param: in out M) is begin null; end P; I: Integer := -1; P(M(I)); Here, I is converted to type M before the call, and converted back to type Integer after the call. It might seem strange for a procedure containing just a null statement to modify its parameter (changing -1 to 255). (On the other hand, floating point types have the same trouble.) In other cases, a call to P would raise Constraint_Error while trying to convert back to the integer type. Consider also modular-to-modular conversions. E.g.: type M1 is mod 4; type M2 is mod 3; Now, should converting from M1 to M2 and back to M1 change the value? Or is it better to consider it an error when the conversion is not reversible (that is, when the original value is 3)? One final example: type T is range -1..100; type M is mod 2**32; If we convert the value 101 of type M to SUBtype T, it will clearly raise Constraint_Error. Should converting 2**32-1 do the same, or should it return -1? - Bob