comp.lang.ada
 help / color / mirror / Atom feed
From: "J-P. Rosen" <rosen@adalog.fr>
Subject: Re: integers of 1, 2, 4 bytes
Date: Mon, 16 Jun 2014 06:46:52 +0200
Date: 2014-06-16T06:46:52+02:00	[thread overview]
Message-ID: <lnlsrs$dmm$1@dont-email.me> (raw)
In-Reply-To: <c06h9rFd1pbU1@mid.individual.net>

Le 15/06/2014 23:25, hreba a écrit :
> All I want is:
> 1. Same behaviour of translated program and original
> 2. Avoid unnecessary range checks.
> 
[...]
> 
> 2. Avoid unnecessary range checks.
> 
> From what I read I had understood the following: Subtypes are always
> range checked, and in addition there are overflow checks. When my
> subtype boundaries are equal to the limits of the base type, one of the
> checks is redundant. I have nothing against checks and I don't have
> performance issues, I just wanted to avoid _unnecessary_ checks.
> 
The Ada model requires checks; however, if a check is unnecessary (i.e.
statically provable as never failing), the compiler is allowed to remove
it, and in practice Ada compilers are quite good at removing unnecessary
checks.

More generally, the design of Ada took great care at not preventing
optimization. So you should not worry about that kind of optimization,
and let the compiler do it for you.

And if you still have doubts, compile the same program with and without
checks, and compare the timings; in general you'll be surprised by how
small the difference is. That's precisely because the compiler removes
all /unnecessary/ checks. All that remains are the /necessary/ checks;
that's why in Ada, you generally keep the tests in the delivered version.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr


  parent reply	other threads:[~2014-06-16  4:46 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 [this message]
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
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