User Defined Ordinal Type
User Defined Ordinal Type
Design Issues
The two most important design issues that are specific to character
string types are the following:
• Should strings be simply a special kind of character array or a
primitive type?
• Should strings have static or dynamic length?
The library operations simply carry out their operations until the null
character appears in the string being operated on.
The character string literals that are built by the compiler also have
the null character. For example, consider the following declaration:
char str[] = "apples";
In this example, str is an array of char elements, specifically apples0,
where 0 is the null character.
If the length of dest is 20 and the length of src is 50, strcpy will write
over the 30 bytes that follow dest. The point is that strcpy does not
know the length of dest, so it cannot ensure that the memory
following it will not be overwritten. The same problem can occur with
several of the other functions in the C string library.
In Java, strings are supported by the String class, whose values are
constant strings, and the StringBuffer class, whose values are
changeable and are more like arrays of single characters. These values
are specified with methods of the StringBuffer class. C# and Ruby
include string classes that are similar to those of Java.
Enumeration Types:
An enumeration type is one in which all of the possible values, which
are named constants, are provided, or enumerated, in the definition.
Enumeration types provide a way of defining and grouping
collections of named constants, which are called enumeration
constants. The definition of a typical enumeration type is shown in the
following C# example:
enum days {Mon, Tue, Wed, Thu, Fri, Sat, Sun};
The enumeration constants are typically implicitly assigned the
integer values, 0, 1, . . . but can be explicitly assigned any integer
literal in the type’s definition.
Array Types:
Design Issues:
The primary design issues specific to arrays are the following:
• What types are legal for subscripts?
• Are subscripting expressions in element references range checked?
• When are subscript ranges bound?
• When does array allocation take place?
• Are ragged or rectangular multidimensioned arrays allowed, or
both?
• Can arrays be initialized when they have their storage allocated?
• What kinds of slices are allowed, if any?