Last Update Time-stamp: "97/08/08 17:18:46 zdu"

Fully Static Dimensional Analysis with C++

This package uses C++ templates to ensure the dimensional correctness of programs at compile-time. Dimensional correctness ensures that all program statements are well-dimensioned, preventing nonsense like adding mass to time.

This package was described in my Sigplan paper (Siplan Notices 29 (9), Sep 1994, pp. 135--139). A similar idea appears in the book Scientific and Engineering C++: An Introduction with Advanced Techniques and Examples, by John J. Barton and Lee R. Nackman, Addison-Wesley, 1994, ISBN 0-201-53393-6. The same authors also described the idea in a article Dimensional Analysis, in C++ Report, Jan 95, pp. 39--43.

After writing the above paper, I found out that the C++ extensions this approach requires (beyond that described in the Annotated Reference Manual (ARM), Ellis & Stroustrup, 1990) are now a standard part of the language and should work with a fully conforming C++ compiler.

The bulk of the package and all its documentation is the header file Dim.h which is automatically generated by m4 from Dim.hm4. There are also a few examples: slide.cc which simulates a block sliding down a inclined plane; the same program with dimensional errors; a program which calculates the period of a simple pendulum; a program which illustrates the use of the package for rational powers.

The package seems to really stress existing C++ compilers; at least the ones I have used. Primarily for that reason, I would regard the package as proof-of-concept, but it could form the basis of a methodology for ensuring the dimensional correctness of C++ programs at compile-time.

You can ftp the entire package, including source and postscript for the Sigplan paper.

Other projects.


Feedback: Please email any feedback to zdu@acm.org.