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,3b4bed4f74b8ac49 X-Google-Attributes: gid103376,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: Re: GNAT messages and the not operator (pitfall alert!) Date: 1996/10/24 Message-ID: #1/1 X-Deja-AN: 191761009 references: organization: New York University newsgroups: comp.lang.ada Date: 1996-10-24T00:00:00+00:00 List-Id: Here is another pitfall, pretty horrible if it hits, but fortunately rare. Ask an Ada expert what is the value of -5 mod 3 Almost anyone (the better they know Ada, the more likely they are to make this mistake) will strain to remember the table in the RM that talks about negative mods, and, if they remember it right, come up with the answer of 1. But Ada has VERY odd precedence rules which mean that the default parenthesiztion of this expression is -(5 mod 3). The only person I ever knew to get this right (and remember this is under conditions they know they are being asked to answer a trick question) was Robert Eachus (both Jean and Tuck got this wrong originally, and so did I :-) A rare error, since this is unusual usage, but still it seems worth another warning (incidentally, try these programs on your own compiler and see what it does -- versions of GNAT before 3.08 are not much help, how do other compilers do :-) Incidentally, this is not a zero probability occurrence, we actually had someone run into this bug recently! Here is the output of GNAT 3.08 on an example program: 1. with Text_IO; use Text_IO; 2. procedure t2 is 3. a : integer := 5; 4. b : integer := 3; 5. 6. begin 7. if -5 mod 3 /= 1 then | >>> warning: unary minus expression should be parenthesized here 8. Put_Line ("Table in RM for negative mods is screwed up"); 9. end if; 10. 11. if (-5) mod 3 /= 1 then 12. null; 13. else 14. Put_Line ("No it isn't!"); 15. end if; 16. end;