Enumerated Types in C∀
Loading...
Date
2024-09-23
Authors
Advisor
Buhr, Peter
Journal Title
Journal ISSN
Volume Title
Publisher
University of Waterloo
Abstract
An enumeration is a type defining a (ordered) set of named constant values.
enum Week { Mon, Tue, Wed, Thu, Fri, Sat, Sun };
enum Math { PI = 3.14159, Tau = 6.28318, Phi = 1.61803 };
enum RGB { Red = 100b, Green = 010b, Blue = 001b };
Its purpose is for readability: replacing constant values in a program with symbolic names that are more meaningful to programmers in the context of the application. Thereafter, associating a name to a different value automatically distributes this rebinding, preventing errors. One of the key properties of an enumeration is the ability to enumerate (iterate) through the constants, and hence, access their values, if present. C restricts an enumeration to the integral type signed int, while C++ extends enumerations to all integral types, meaning enumeration names must bind to integer constants. Other modern programming languages provide bindings to any type and additional features to extend enumeration capabilities for better software engineering practices.
The C∀ (C-for-all) programming language is an evolutionary refinement of the C programming language. One of its distinctive features is a parametric-polymorphic generic type. However, legacy data types from C, such as enumerations, do not adapt well to the C∀ generic type system.
This thesis extends the simple and unsafe enumeration type in the C programming language into a complex and safe enumeration type in the C∀ programming-language, while maintaining backwards compatibility with C. The major contribution is an adaptation of enumerated types with the C∀ type-system in a way that integrates naturally with the generic types. This thesis also presents several smaller refinements to the C∀ overload resolution rules for enumerated types, each of which improves the intuitive nature of enumeration name resolution by the compiler. Finally, this work adds other useful features to enumerations that better support software engineering practices and simplify program development.
Description
Keywords
programming languages, language design, language implementation, enumerated types