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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.236.72.197 with SMTP id t45mr248975yhd.44.1402933091914; Mon, 16 Jun 2014 08:38:11 -0700 (PDT) X-Received: by 10.50.28.77 with SMTP id z13mr472721igg.10.1402933091720; Mon, 16 Jun 2014 08:38:11 -0700 (PDT) Path: border1.nntp.dca1.giganews.com!buffer1.nntp.dca1.giganews.com!border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!i13no3019041qae.1!news-out.google.com!gf2ni0igb.0!nntp.google.com!h3no4565617igd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 16 Jun 2014 08:38:11 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <17b7513f-2ccb-47ef-8589-661cb62b3dd9@googlegroups.com> Subject: Re: integers of 1, 2, 4 bytes From: Adam Beneschan Injection-Date: Mon, 16 Jun 2014 15:38:11 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Original-Bytes: 3024 Xref: number.nntp.dca.giganews.com comp.lang.ada:186973 Date: 2014-06-16T08:38:11-07:00 List-Id: On Sunday, June 15, 2014 10:57:31 AM UTC-7, hreba wrote: > Hi, >=20 > I want to translate some of my Oberon programs to Ada. >=20 > So I need the Oberon types SHORTINT (1 byte), INTEGER (2 bytes) and=20 > LONGINT (4 bytes). A type BYTE (1 byte, values 0..255) would be useful=20 > too. In Oberon one uses CHAR for that. >=20 > The most obvious translation for INTEGER would be >=20 > type INT is range -32768 .. 32767; >=20 > (all platforms I have been working on use the two's complement). >=20 > My Ada book says that range checks are applied to constrained subtypes=20 > (like that one) but not to unconstrained subtypes, but but overflow=20 > checks are applied nevertheless. So I came up with >=20 > type Int16 is range -32768 .. 32767; > for Int16'Size use 16; > type INT is new Int16'Base; >=20 > as a more efficient definition. You normally shouldn't care about the size. The only times you should real= ly care about the size are (1) this integer type will be part of a data str= ucture whose layout *must* look a certain way because the data structure wi= ll be read/written to a file or a socket or something; (2) the data will be= used by non-Ada code that expects it to be a certain size; (3) you have lo= ts of data and limited memory, and you need to ensure that the size is as s= mall as possible even if it means that it will take longer to work with the= data. Otherwise, you don't need to specify the size. =20 type Int is range -(2**15) .. 2**15-1; will let the compiler know that the values won't be outside that range, and= it can use the information to help decide what's more efficient. Which ma= y still be a 32-bit integer, on many processors. -- Adam