Chapter 4 -- Types

The purpose of types The basic types are those types built into the language, not including any standard libraries.  They include
char, short, int, long, float, double, String, enum, boolean, etc.
Question about basic types:
    Can you assign float a= 10;
    Can you assign char a = 10;
    What is 10 % -3 (1 or -2)
    What is EOF, and int or a char?
Enums
Are finite sequences of named values (Mon, Tues,day, Wed).
Can a name appear in more than one enum (no says C and Pascal).
Normally have an ordering.
Can sometimes be used in mathematical expressions (Mon + 3 == Thru)
Booleans
Are either true of false
Question:  Should boolen expressions short circuit ( a != 0 && 3/a > 10)
       If no, then this code doesn't work.
Arrays
are generally an association of values all the same type and an index value (which is an int).
Have their location computed by (base + index * size_of_one_element)
Can have multiple indexes (base + index1 * sizeof_one + index2 * sizeof_one * max_value_of_index1)
Some languages check the bounds are run time (Pascal, Ada) and others do not.
Some language have a bas index value of 0, some 1, and some allow it to be declared by the programmer.
Does each sized array make a new type???
    1qFor some languages the bounds must be known at compile time (C) or run time (c++).
Question:  Does array assignment work (arrayA = arrayB)
Records
Are a collection of possibly different types all treated together as a single unit.
In most langauges the layout as described by the code need not be the layout in RAM or on disk.
Unions (Varient Record)
A union is a collection of different types that share a common storage location.  Only one part of a union can hold a value at a time.
Save space compared to records.
Sometimes have a 'tag' that tells what part of the union is active at any time.
Are sometimes called 'varient records'.
Allow a backdoor around the type system.
Have been replaced by polymorphic objects.
Sets
A collection of objects (normally of a simple type)
Would be great for several classes of problems (misspelled words, for instance).
Implemented via bit arrays, arrays of entries, linked lists, etc.
Operations:  union, intersection, difference, symetric difference.
Pointers
Normally quicker to move around than the pointed-to object.
Very useful for many data structures (linked, lists, trees, etc).
Question:  What does a pointer in Java look like?  In C++?
Strings
Not builtin to C or C++ or Pascal
Builtin to most languages, however.
Can be represented by char array followed by a zero, or by length+array
Ranged Types
Useful for minutes,hours, ounces, etc.
Built out of ints, enums, but not reals.
Can be useful for index ranges.
Objects
Union with functions.
Free Form Languages
Some languages do not make the programmer state the type.  Perl and Lisp let you store scalure  in any variable.  If some operator does not apply to the currently held value, then the program crashes.
OLD basic assumed the type from the variable name.  A$ was a string, A% was an int, A, was a float.  Fortran assumes I-N are intes, rest floats.