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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bf6949b8c20fe97 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-03-06 04:06:29 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!newsfeed3.easynews.com!easynews.com!easynews!newsfeed.news2me.com!wn51feed!worldnet.att.net!attbi_s52.POSTED!not-for-mail From: "Jeff C," Newsgroups: comp.lang.ada References: <464ad5ee.0403060145.6c03b8d9@posting.google.com> Subject: Re: Semantic of the mod operator in Ada 83 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: NNTP-Posting-Host: 24.147.74.171 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s52 1078574741 24.147.74.171 (Sat, 06 Mar 2004 12:05:41 GMT) NNTP-Posting-Date: Sat, 06 Mar 2004 12:05:41 GMT Organization: Comcast Online Date: Sat, 06 Mar 2004 12:05:41 GMT Xref: archiver1.google.com comp.lang.ada:6105 Date: 2004-03-06T12:05:41+00:00 List-Id: "SPHINX" wrote in message news:464ad5ee.0403060145.6c03b8d9@posting.google.com... > I just wander what is the semantic of > What is the exact semantic > of the function mod in that case? > -- Compiler is gnat 3.15 > -- modular types are not used, because the mode shall be Ada83 > > with text_io; > use text_io; > procedure counter is > Size : constant := 32; > type Counter is range 0 .. (2 ** 31) - 1; -- = 0..2147483647 > for Counter'Size use Size; > > V1 : Counter := Counter'LAST; > V2 : Counter := Counter'LAST; > R : Counter := 0; > Z : Counter := 0; > function Add (Val1 :in Counter;Val2 :in Counter) return Counter is > begin > return ((Val1+Val2) mod Counter'Last); > end Add; > package counter_io is new integer_io(Counter);use counter_io; > begin > put("V1="); counter_io.put(V1);new_line; > put("V2="); counter_io.put(V2);new_line; > R := Add (V1, V2); > put("R=");counter_io.put(R);new_line; > --Result for GNAT 3.15 => R=-2 > put("LAST=");put(Counter'Last);new_line; > R := V1+V2; > put("R=");counter_io.put(R);new_line; > Z := R; > put("Z=");counter_io.put(Z);new_line; > end counter; > > And why there is no containt error on the direct additions > Thanks for the help I am a little confused about what you are asking given the title and the message contents but I'll take a shot. One thing you are asking is why is there no constraint error on the addition. As it turns out there is. This code is not really valid and does not do what it thinks it does. The reason you are not getting a contraint_error is likely that you are compiling without the -gnato flag. For various reasons, the people that implemented GNAT decided to leave integer overflow checking OFF with the default set of compiler switches. Delete your .exe and .o files and try gnatmake -gnato counter And see what you get (I don't have 3.15 installed but I suspect you will indeed get your constraint error). As for the semantic of the mod operator in Ada 83 (and 95). Look here http://archive.adaic.com/standards/83rat/html/ratl-05-02.html In general though it is not clear to me that using rem and mod with a right hand side equal to the type'last (especially when used as this code is doing) is going to do anything useful at all.