Compatible Type:
Type Binding are Static - Type checking
done by compiler.
Type Binding are Dynamic - Run time checking type.
Strong Typing:
If typed errors
are always detected either at compile time or run time.
examples:
Not strongly typedType Compatibility Checking:FORTRAN - the relationship between actual and formal parameters is not type checking.Nearly strongly typed
the use of EQUIVALENCE allows one variable to refer to a value of different type.
C, C++ - functions do not have to have parameter type checked.
UNION types are not type checked.Pascal - good, except variant records.Strongly typed
Ada - dynamically checks for correct types values
- use UNCHECKED_CONVERSION to get rid of checking.
Modula-3 - LOOPHOLE same as UNCHECKED_CONVERSION in Ada.ML - all variables have statically know type.
JAVA - based on C++, like Ada (in terms of type checking)
Error can occur explicitly, not implicitly.
There are two methods for checking type compatibility.
1. NAME TYPE: the type name must match.e.g.
2. STRUCTURE TYPE: underlying structure must match.
type indextype = 1.. 100; {a subrange type}
var
count : integer;
index : indextype;count and index are not NAME TYPE compatible. It is STRUCTURE TYPE compatible.
e.g.
type
type1 = array [1..10] of integer;
type2 = array [1..10] of integer;
type3 = type2;If we do not use STRUCTURE TYPE compatibility, type1 and type2 are not compatible.
Using declaration equivalence, we say type2 and type3 are compatible.e.g.
type celsius is new FLOAT;
type fahrenheit is new FLOAT;By NAME TYPE compatibility, they are not same.
Ada using derived type checking, gets avoid name type checking.C:
use structure equivalence except for record & union (these two are declaration equivalence)
C++:
use name equivalence.
FORTRAN:
can not use name equivalence.
COBOL:
can not use name equivalence.
can not define and name types.