Adtpp: lightweight efficient safe polymorphic algebraic data types for C. (13th May 2016) - Naish, Lee; Schachte, Peter; MacNally, Aleck M.
Summary: Adtpp is an open‐source tool that adds support for algebraic data types (ADTs) to the C programming language. ADTs allow more precise description of program types and more robust handling of data structures than are directly supported by C. ADT definitions and other declarations are put in a file that is preprocessed byadtpp to produce a C header ('.h') file that can be included in C source files. The generated header file contains C type definitions, macros, and inline functions that support type‐safe construction, deconstruction, and pattern matching of ADT values while avoiding unsafe operations such as casts, and avoiding the risk of errors such as dereferencing NULL pointers and accessing inappropriate fields of unions. Values are represented efficiently, using techniques from the implementation of declarative languages. For many simple data types, the memory representation is identical to a direct implementation in C, with no loss of efficiency. For more complex types, theadtpp representation is more efficient than common C representations while preserving type safety and convenience. As an example, we present a new variation of 234‐trees that is very compact.Adtpp also supports parametric polymorphism such as defining a type 'list of t ', where t can be any ADT, and generic functions such as length. However, polymorphic code is somewhat more verbose than for typical declarative languages, due to our reliance on the limited type checking available in C. Copyright © 2016 John Wiley & Sons, Ltd.