3 Records

Although C/C++ (and many other languages) support native record types, most record type implementations are restrictive compared to the abstract description of a record. Let us consider the language construct struct of C (about the same applies to class in C++).

First of all, a struct definition in C is static. In other words, a program cannot add or delete data members of a struct at run time. Second, the type of data for each data member is also fixed at compile time.

The restrictions of a struct in C are there for good reasons: efficiency and ease of compiler implementation. struct is a huge step forward from what programmers have to do in assembly language programming. In other words, struct restrictions are, for the most part, justifiable and reasonable.

As an abstract data type, however, struct has too many implementation-based restrictions. This section explores the interface of a record ADT, and also how it may be implemented.

For those who are curious about alternative implementations of records, Perl has an interesting perspective of records. Instead of making records a compile-time construct, a record in Perl is a ``hash''. A ``hash'' is similar to a ``map'' as defined in the C++ STL (standard template library), only that a ``hash'' is even more flexible.



Subsections
Copyright © 2006-09-13 by Tak Auyeung