Anders' Ada software page

Feel free to drop me an e-mail if you find some of this software useful or have other comments or suggestions.


Ada Add Finalization Anywhere Library (GPL) EXPERIMENTAL

Note: This hack should not be needed in Ada 2005. (If you still think you need it you are most likely doing something wrong..)

In Ada 95 controlled types, i.e. types with user defined initialize and finalize operations, must be declared at the library level - either as direct descendents of Ada.Finalization./Limited_/Controlled or via a mixin component that inherits from Ada.Finalization./Limited_/Controlled. This sometimes makes the usage of controlled types a bit of a hassel, and in particular, prevents the use of controlled types in generic packages that one would like to be able to instantiate at deeper levels than the library level.

This library, the Add Finalization Anywhere Library, aims to provide a nice(?) way to add finalization to any limited tagged type at any level. The structure of the library is inspired by Christoph Karl Walter Grein's library for adding finalization to library level limited tagged types and my library is designed to integrate well with the structure of his.

Since declaring controlled types elsewhere than at the library level isn't directly supported by Ada 95 there are some potentially dangerous things going on inside my library. Currently, I don't know for sure if my code works on other compiler than GNAT 3.15p (on Linux and Solaris) and if it is safe.

However, as far as my understanding of the Ada 95 RM and compilers go I do not find it unlikely that this approach could work in many cases. As far as I can see the only potential problem is the unchecked conversions back and forth between an access to tagged record type and System.Storage_Elements.Integer_Address, which need to be done in order to associate an object of a "controlled" non-library-level type with its mixin component of a "real" library-level controlled type.

This is experimental code! Try it if you dare and let my know whether it works on you platform/compiler or not. And check the known bugs below!


Known bugs:

(Last updated: 2004-09-22)

back to Anders' home page

Valid HTML 4.01! Valid CSS!

Email: anders-www [at]
Comments and suggestions are welcome!