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-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news.glorb.com!feeder.erje.net!de-l.enfer-du-nord.net!gegeweb.org!aioe.org!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: unsigned type Date: Sun, 28 Jun 2009 19:54:28 +0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: <59O1m.404661$4m1.69194@bgtnsc05-news.ops.worldnet.att.net> NNTP-Posting-Host: jsj6/wjO/cHSAHkcGxcp1Q.user.aioe.org X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.7.9 X-Newsreader: Tom's custom newsreader Cancel-Lock: sha1:f7gSyjwJ0/w82Bf34JFDBGPdK2o= Xref: g2news2.google.com comp.lang.ada:6688 Date: 2009-06-28T19:54:28+00:00 List-Id: >I am trying to declare a type as unsigned using Ubuntu 9.04 GNAT >compiler. I know Ada does not have a type CARDINAL, but I thought it >had a type Unsigned. Ada's equivalent is Natural. If Lowest : Natural := 0; Highest : Natural := Natural'last; then Lowest := Lowest-1; -- will raise an exception Highest := Highest+1; -- ditto (Note that Gnat by default is not a legal Ada compiler because it doesn't check for and raise the exception. You need a command line parameter -gnato to make it act like Ada.) The standard Ada package Interfaces has hardware-oriented types Unsigned_8, Unsigned_16, etc but those are modular types so if Empty_Word : Interfaces.Unsigned_16 := 0; Full_Byte : Interfaces.Unsigned_8 := 255; then Empty_Word-1 will be 65535. Full_Byte+1 will be 0. with no exceptions raised. You can also declare your own application oriented non-negative types type Ratings is range 1 .. 10; or modular types type Degrees is mod 360; -- 0 .. 359 wrapping around