comp.lang.ada
 help / color / mirror / Atom feed
From: "REH" <spamjunk@stny.rr.com>
Subject: Re: Type safety, C++ and code generation
Date: 27 Apr 2006 06:19:14 -0700
Date: 2006-04-27T06:19:14-07:00	[thread overview]
Message-ID: <1146143954.169807.207080@t31g2000cwb.googlegroups.com> (raw)
In-Reply-To: <e2q6p8$idj$1@sunnews.cern.ch>


Maciej Sobczak wrote:
> Hi,
>
> I have developed a simple code generator that helps me significantly
> raise the level of type safety in C++:
>
> http://www.msobczak.com/prog/typegen/
>
> The whole idea was in some way inspired by Ada, so I hope to get some
> constructive criticism and comments from you - that's why I post it
> here. Please look at it from the perspective of Ada programmer.
>
> (And taking into account the fact that some of you are also C++
> programmers, you might actually find it interesting or even useful.)
>
> --
> Maciej Sobczak : http://www.msobczak.com/
> Programming    : http://www.msobczak.com/prog/

You maybe interested in a C++ class that I wrote.  It creates range and
overflow checked integer types.  The interesting thing about the class
is that it uses templates to do static analysis on expressions to
remove unnecessary checks at compile time.

For example:

typedef ranged_type<unsigned, 0, 100> R;
R x, y, z;  // The variables are defaulted to the
            // minimum of the range which in this
            // case is 0.  Sometime later these
            // variables are initialized.  Their
            // actual values do not matter for
            // this example.

const R a = 5, b = 7, c = 1;
R r = ((x + a) * (y + b)) / (z - c);

For the above, all overflow checks are removed, except for
divide-by-zero, negative values on the subtraction, and the upper range
of the result when assigning to r.

If you are interested, it can be found here:
http://www.richherrick.com/software/herrick_library.html


REH




  reply	other threads:[~2006-04-27 13:19 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-27 10:35 Type safety, C++ and code generation Maciej Sobczak
2006-04-27 13:19 ` REH [this message]
2006-04-27 14:08   ` Maciej Sobczak
2006-04-27 14:33     ` REH
2006-04-27 15:16       ` Maciej Sobczak
2006-04-27 15:39         ` Georg Bauhaus
2006-04-28  5:57           ` Maciej Sobczak
2006-04-28 12:16             ` Georg Bauhaus
2006-04-28 12:37               ` brian.b.mcguinness
2006-04-28 17:04                 ` Georg Bauhaus
2006-04-28 18:50                 ` Jeffrey R. Carter
2006-04-28 19:07                   ` Randy Brukardt
2006-04-28 19:46                     ` Robert A Duff
2006-04-28 19:55                   ` Dmitry A. Kazakov
2006-04-29 21:28               ` Florian Weimer
2006-04-27 16:05         ` REH
2006-04-28  6:17           ` Maciej Sobczak
2006-04-30 14:40         ` adaworks
2006-04-30 15:23           ` REH
2006-04-30 18:14         ` Martin Krischik
2006-05-02  6:27           ` Maciej Sobczak
2006-05-02 13:33             ` REH
2006-05-02 15:05               ` Maciej Sobczak
2006-05-02 15:54                 ` REH
2006-05-02 16:50               ` Martin Krischik
2006-05-02 19:50                 ` REH
2006-04-27 14:47     ` REH
2006-04-27 15:10     ` REH
2006-04-28  6:22       ` Maciej Sobczak
replies disabled

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