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: dewar@cs.nyu.edu (Robert Dewar) Subject: Re: DECAda/VMS - calling GETJPI Date: 1996/06/03 Message-ID: #1/1 X-Deja-AN: 158251547 references: <31B2AF74.668E@dial.eunet.ch> <4ouo97$pe8@gcsin3.geccs.gecm.com> <4ouuuv$6hd@linus.mitre.org> organization: Courant Institute of Mathematical Sciences newsgroups: comp.lang.ada Date: 1996-06-03T00:00:00+00:00 List-Id: Micheal Brenner said: "you could just assign it: integer_minus_1: integer := -1; x: unsigned_longword := unsigned_longword (integer_minus_1); because Ada 95 modular types truncate numbers to their modular range without giving a constraint_error." That's quite wrong, the type conversoin checks that the value is in range, and the value is outside the range. Indeed if you add a constant to the declaration of integer_minus_1, the out of range condition will be detected at compile time by GNAT: 1. procedure z is 2. type ul is mod 2 ** 64; 3. integer_minus_1: constant integer := -1; 4. x: ul := ul (integer_minus_1); | >>> warning: static value out of range of type "ul" defined at line 2 >>> warning: "constraint_error" will be raised at runtime 5. begin 6. null; 7. end; Yes, you can apply the unary minus operator to an unsigned vaue and get modular results as expected, but here the minus is applied to a signed type and generates a real minus one, which is definitely outside the range of any unsigned type. It's probably time again to repost the plea that if you suggest a solution to a problem, compile an example and make sure it works. No one is realiable enough to be 100% accurate without such a backup check, and posting incorrect information on Ada can cause a lot of confusion! IN fact the proper solution in this case is trivial: procedure z is type unsigned_longword is mod 2 ** 64; x: unsigned_longword := -1; begin null; end; or, if you want the constant integer_minus_1, define it as type ul to start with.