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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b2923d60cb81694b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!tiscali!newsfeed1.ip.tiscali.net!news.tiscali.de!newsfeed.hanau.net!noris.net!news2.arglkargh.de!nuzba.szn.dk!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Unsigned Integer Restraint Errors Date: Mon, 12 Mar 2007 14:22:04 -0500 Organization: Jacob's private Usenet server Message-ID: References: <1173712032.183064.264340@8g2000cwh.googlegroups.com> <1173726806.656979.305660@8g2000cwh.googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: jacob-sparre.dk 1173730826 24607 69.95.181.76 (12 Mar 2007 20:20:26 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Mon, 12 Mar 2007 20:20:26 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 Xref: g2news1.google.com comp.lang.ada:14494 Date: 2007-03-12T14:22:04-05:00 List-Id: "frikk" wrote in message news:1173726806.656979.305660@8g2000cwh.googlegroups.com... > Thank you for the input. This leaves me with 2 questions: > 1. If my input is 2**35, wouldn't this still render the Integer type > inaccurate? The goal is to be able to use 64 bit integers... I'm > referring to your example of UNSIGNED_LONG_INT := UNSIGNED_LONG_INT > (Integer'(X)); The real problem here is that you are trying to use modular types in a checked way. As others have noted, they're not really intended for that. It's best to avoid using modular types such that they'll raise an exception. Ada has signed, checked integers, and unsigned, unchecked integers. It doesn't have unsigned, checked integers. That omission is only a problem if you need checked, maximum range unsigned integers; usually, you should just use an appropriate signed integer type: type Really_Big_Unsigned_Int is range 0 .. 2**63-1; This type will have the overflow and range checking you've looking for. Even better is to replace the upper bound by something that is appropriate for your application: Max_Widgets : constant := 2**40; type Widget_Count is range 0 .. Max_Widgets; The only problem here is that your upper bound has to be somewhat smaller than the maximum allowed. Given the immense range of 64-bit integers, I have a hard time imagining a case where that would be a problem (it's rarely a problem even for 32-bit integers). Note that this sort of declaration will work on any Ada compiler that supports 64-bit numbers, and if it doesn't, you'll get a convenient error message. Randy.