Concepts of Programming Languages

(Sean Pound) #1

246 Chapter 6 Data Types


predefined types. In object-oriented languages, every instance of every class,
whether predefined or user-defined, is called an object. Objects are discussed
in detail in Chapters 11 and 12.
In the following sections, many common data types are discussed. For most,
design issues particular to the type are stated. For all, one or more example
designs are described. One design issue is fundamental to all data types: What
operations are provided for variables of the type, and how are they specified?

6.2 Primitive Data Types


Data types that are not defined in terms of other types are called primitive
data types. Nearly all programming languages provide a set of primitive data
types. Some of the primitive types are merely reflections of the hardware—for
example, most integer types. Others require only a little nonhardware support
for their implementation.
To provide the structured types, the primitive data types of a language are
used, along with one or more type constructors.

6.2.1 Numeric Types


Many early programming languages had only numeric primitive types. Numeric
types still play a central role among the collections of types supported by con-
temporary languages.

6.2.1.1 Integer
The most common primitive numeric data type is integer. Many comput-
ers now support several sizes of integers. These sizes of integers, and often
a few others, are supported by some programming languages. For example,
Java includes four signed integer sizes: byte, short, int, and long. Some
languages, for example, C++ and C#, include unsigned integer types, which are
simply types for integer values without signs. Unsigned types are often used
for binary data.
A signed integer value is represented in a computer by a string of bits, with
one of the bits (typically the leftmost) representing the sign. Most integer types
are supported directly by the hardware. One example of an integer type that
is not supported directly by the hardware is the long integer type of Python
(F# also provides such integers). Values of this type can have unlimited length.
Long integer values can be specified as literals, as in the following example:

243725839182756281923L

Integer arithmetic operations in Python that produce values too large to be
represented with int type store them as long integer type values.
Free download pdf