comp.lang.ada
 help / color / mirror / Atom feed
From: Martin Krischik <krischik@users.sourceforge.net>
Subject: Re: where exactly c++,c fail and Ada gets thru'
Date: Sat, 29 Apr 2006 09:03:59 +0200
Date: 2006-04-29T09:03:59+02:00	[thread overview]
Message-ID: <1201812.r16X2gYOJE@linux1.krischik.com> (raw)
In-Reply-To: e2t1ne$n3i$1@sunnews.cern.ch

Maciej Sobczak wrote:

> Martin Krischik wrote:
> 
>> The point is - of corse -  it that the semantic tree of the Ada
>> compiler contains the information that X will be in the range of (1 ..
>> 5) and then the optimizer can easily calculate that (1 .. 5) + 3 < 10
>> and then optimize away the check.
>> 
>> The sematinc tree of the C++ will contain the information that X is in
>> the range of (-2*32 .. +2*32-1) and that is a pretty useless
>> information to the optimizer.
> 
> Except that the optimizer is not limited to use only this information.
> With the two example ranges (1..5 and 1..10) the result of inlining will
> be that the following operations - all operating on the single value -
> will be placed one after another:
> 
> 1. compare against 5
> 2. add 3
> 3. compare against 10
> 
> It doesn't take a rocket scientist to deduce that the third operation
> has a dead branch and can be therefore eliminated.

But it is the callers responsibility to check the input parameter before
calling the function. That way range checks need only be performed on input
and type convertions. Remember that Ada defines + as:

function "+" is (L, R: in Integer'Base) return Integer'Base;

Back to my example: If you call F(3) no check is needed. The caller knows
that 3 is in range and the callee knows that X + 3 is in range. Of course:
If the optimizer spots that is a different story.

Now I do wonder if REH managed some template/boolean magic to get the same
result on C++. 

Martin
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com



  reply	other threads:[~2006-04-29  7:03 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-24  4:19 where exactly c++,c fail and Ada gets thru' Ananth the Boss
2006-04-24  5:05 ` jimmaureenrogers
2006-04-24  7:45   ` Ananth the Boss
2006-04-24 19:17   ` Martin Krischik
2006-04-24 20:23   ` Simon Wright
2006-04-24 22:34     ` Keith Thompson
2006-04-24 22:33   ` Keith Thompson
2006-04-25  5:23     ` Jeffrey R. Carter
2006-04-26 17:48     ` Martin Krischik
2006-04-26 19:33       ` Keith Thompson
2006-04-26 15:10   ` Maciej Sobczak
2006-04-26 17:32     ` Martin Krischik
2006-04-27 10:07       ` Maciej Sobczak
2006-04-27 21:19         ` Keith Thompson
2006-04-28  7:00         ` Martin Krischik
2006-04-28 12:27           ` Maciej Sobczak
2006-04-29  7:03             ` Martin Krischik [this message]
2006-04-29 14:08               ` REH
2006-05-01 10:20                 ` Xcriber51
2006-05-01 13:55                   ` REH
2006-05-02  6:43               ` Maciej Sobczak
2006-04-27 16:48       ` REH
2006-04-28  7:49         ` Martin Krischik
2006-04-28 11:17           ` REH
2006-04-29  6:47             ` Martin Krischik
2006-04-24  8:13 ` Rod Chapman
2006-04-25  1:57 ` Steve
replies disabled

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