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-Thread: 103376,fc8384b47d495708 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 23 Jul 2004 22:33:14 -0500 Message-ID: <4101D87A.8040609@comcast.net> Date: Fri, 23 Jul 2004 23:33:14 -0400 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada To: kboruff@optonline.net Subject: Re: Should be getting a constraint error in this code References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.147.90.114 X-Trace: sv3-jPGDHjmGijxt7t6/Eweg241p7RfREItdioXm2UgFaEk02Q18rD2FSUnfUjVKvk7PpMoMWuLYZKyCF4x!mKd0HpswoNmovaRJIhR0fcSj9YOUC7OGS+FKi3t7x3baWFGp1FodCw== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: g2news1.google.com comp.lang.ada:2369 Date: 2004-07-23T23:33:14-04:00 List-Id: Keith Boruff wrote: > Hey all, > > Forgive me for posting such a trivial problem here but I couldn't seem > to find an answer in any of the FAQs I know of nor DejaNews. > > Though I'm not a novice programmer, I am a novice Ada programmer. I suspect that the problem is that you are using GNAT, and forgot to read the fine manual. If you expect integer overflow to be detected, you need to run gnatmake -gnato The historical reasons for this are now ancient history. The alternative is to use pragma Unsuppress. If you insert it here: > > In my studies this evening, I wrote the following trivial program to > force a constraint error: > > with Ada.Text_Io; use Ada.Text_Io; > > procedure Constraint_Tests is pragma Unsuppress(Overflow_Check); > > type Exam_Mark is range 0 .. 100; > > English : Exam_Mark := 72; > Math : Exam_Mark := 68; > Computing : Exam_Mark := 76; > Average : Exam_Mark; > > begin > > Put("Average exam mark is "); > > -- I expect a constraint exception in this statement > -- because English + Math + Computing > 100 > -- NOTE: On my machine, Exam_Mark'Base'Last = 127 > Average := (English + Math + Computing) / 3; > Put_line(Exam_Mark'Image(Average)); > > end Constraint_Tests; > > > Ok, the problem I'm having is that I'm expecting a constraint exception > to occur because (English + Math + Computing) = 216 and the largest > value of its base is 127 (on my machine). Then you should get the result you expect. I get: F:\Ada\Test>constraint_tests constraint_tests Average exam mark is raised CONSTRAINT_ERROR : constraint_tests.adb:21 overflow check failed with either pragma Unsuppres, or -gnato, and 243 without. -- Robert I. Eachus "The flames kindled on the Fourth of July, 1776, have spread over too much of the globe to be extinguished by the feeble engines of despotism; on the contrary, they will consume these engines and all who work them." -- Thomas Jefferson, 1821