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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,635cd9622b25ae59 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!t31g2000cwb.googlegroups.com!not-for-mail From: "REH" Newsgroups: comp.lang.ada Subject: Re: Type safety, C++ and code generation Date: 27 Apr 2006 06:19:14 -0700 Organization: http://groups.google.com Message-ID: <1146143954.169807.207080@t31g2000cwb.googlegroups.com> References: NNTP-Posting-Host: 192.91.173.36 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1146143959 16097 127.0.0.1 (27 Apr 2006 13:19:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 27 Apr 2006 13:19:19 +0000 (UTC) In-Reply-To: User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: t31g2000cwb.googlegroups.com; posting-host=192.91.173.36; posting-account=lnUIyw0AAACoRB2fMF2SFTIilm8F10q2 Xref: g2news2.google.com comp.lang.ada:3951 Date: 2006-04-27T06:19:14-07:00 List-Id: 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 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