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=unavailable autolearn_force=no version=3.4.4 Path: buffer2.nntp.dca1.giganews.com!border2.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!news.bbs-scene.org!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Carter Newsgroups: comp.lang.ada Subject: Re: integers of 1, 2, 4 bytes Date: Sun, 15 Jun 2014 15:09:59 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 15 Jun 2014 22:10:00 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="ba346f17b503f6aa8ecbfd6d1e2a9f59"; logging-data="27805"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IS9e8wbdsrIovTwcRE2jL6WbGz2oACfI=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: Cancel-Lock: sha1:nNCES1ZmwtwyoLFlckjOX1xbjKg= X-Original-Bytes: 2343 Xref: number.nntp.dca.giganews.com comp.lang.ada:186944 Date: 2014-06-15T15:09:59-07:00 List-Id: On 06/15/2014 10:57 AM, hreba wrote: > > My Ada book says that range checks are applied to constrained subtypes (like > that one) but not to unconstrained subtypes, but but overflow checks are applied > nevertheless. So I came up with > > type Int16 is range -32768 .. 32767; > for Int16'Size use 16; > type INT is new Int16'Base; > > as a more efficient definition. This is a (probably) failed attempt at premature optimization, and might not be what you want. Int is likely to be exactly the same as Int16; if it isn't, it's probably because Int16'Base is 32 bits. So you should simply define the types you need in the most natural, readable way possible, and not worry about "efficiency" until such time as you are unable to meet your timing requirements. In Ada, "the most natural, readable way" usually means defining types based on the problem, not based on the predefined types that a compiler happens to implement. -- Jeff Carter "This trial is a travesty. It's a travesty of a mockery of a sham of a mockery of a travesty of two mockeries of a sham. ... Do you realize there's not a single homosexual on that jury?" Bananas 27