Chapter 5:Semantic Analysis

Type systems .

. Static typing

- Catches most common programming errors at compile time

- Avoids runtime overhead

- May be restrictive in some situations

- Rapid prototyping may be difficult

. Most code is written using static types languages

. In fact, most people insist that code be strongly type checked at compile time even if language is not strongly typed (use of Lint for C code, code compliance checkers)

There are several advantages of static typing:

. Most of the error in the program is caught at the compile time only.

. Since type checking at run time is not involved, therefore runtime type checking overhead is avoided.

Most of the programming is done generally in statically typed languages because of above mentioned advantages. However, there are also certain drawbacks of static typing:

. It can be restrictive in certain situations. For example, in Pascal, all the identifers

. are identified by a unique name. This can give rise to confusion in many cases.

. Rapid prototyping of statically typed programs can be difficult, since one has to ensure that the types are correct when prototyping in order that the code compiles

Disadvantages notwithstanding, most programmers emphasize that the code should be strongly type checked at compile time even if the language is not strongly typed. For example, Lint can be used to strong type checking of C programs.