comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: integers of 1, 2, 4 bytes
Date: Sun, 15 Jun 2014 15:09:59 -0700
Date: 2014-06-15T15:09:59-07:00	[thread overview]
Message-ID: <lnl5jn$r4t$2@dont-email.me> (raw)
In-Reply-To: <c0654eFaetvU1@mid.individual.net>

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


  parent reply	other threads:[~2014-06-15 22:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-15 17:57 integers of 1, 2, 4 bytes hreba
2014-06-15 18:43 ` Dmitry A. Kazakov
2014-06-15 20:52   ` hreba
2014-06-15 19:07 ` Niklas Holsti
2014-06-15 21:25   ` hreba
2014-06-15 22:39     ` Georg Bauhaus
2014-06-16 13:37       ` AdaMagica
2014-06-16  4:46     ` J-P. Rosen
2014-06-15 19:26 ` Stefan.Lucks
2014-06-15 21:31   ` hreba
2014-06-15 21:55     ` Niklas Holsti
2014-06-15 22:09 ` Jeffrey Carter [this message]
2014-06-16 15:38 ` Adam Beneschan
2014-06-16 17:27 ` gautier_niouzes
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox