Previous section   Next section

Imperfect C++ Practical Solutions for Real-Life Programming
By Matthew Wilson
Table of Contents
Part Three.  Language Concerns


Chapter 13. Fundamental Types

Conceptually, a type is defined by a set of values and the operations that may be performed on those values. This is a widely accepted notion of type, and represents the minimum strict definition.

In practice, however, the correct manipulation of types depends not just on a balance between suitability—fitness for purpose—and expressiveness, but also on safety and even "human" factors such as its name. It is important that a type provides you with enough power and flexibility to enable you to clearly and efficiently represent and manipulate the concept you require, but equally important that the range of operations is restricted to a safe and predictable set.

The fundamental types (see Prologue) provided by C++ come from C [Kern1988]. Apart from the bool type, which has been added to C++ (the C++-98 standard) and to C (as of the C99 standard), this list has remained largely unchanged from the early days of the language [Stro1994]. As such, there are several subtle hazards associated with the use of these types. Furthermore, the list is a little dated, and there are a number of types that could usefully be added to it.

This chapter looks at some new types that could be useful enhancements to the language and the ways in which they may be provided within the bounds of the current language. We'll also take a look at some problems that we can encounter when using fundamental types, including bool which is often more trouble than it's worth (as we discuss in sections 13.4.2 and 15.3).


      Previous section   Next section