Type Safety

In computer science, a programming language is type safe when the language does not permit the programmer to treat a value as a type to which it does not belong. This generally requires that the language have a complete specification of its semantics; this in turn implies that programs written in that language follow the specification regardless of what machine it is run on. Safety is a property of the programming language, however, and not of the programs themselves. For example, it's possible to have a safe program written in a type-unsafe language. Type safety is synonymous with one of the definitions of strong typing. Subsets of ML and Java have been mathematically proven to be type-safe (however, certain errors may occur at runtime due to bugs in the implementation, or in linked libraries written in other languages). The C programming language is the archtypical type-unsafe language due to casting, particularly the casting of pointers to void pointers and back. More recent implementations of C perform some compile-time type-checking, making the language much more type-safe than it was in its early days. However, the compiler only issues warnings, and the user is still free to perform arbitrary casts that destroy type safety. In order for a language to be completely type-safe, even against adversaries, it typically needs to have garbage collection. It is possible to make a language type-safe without garbage collection, but it can be difficult. The reason is rather technical: suppose that a strongly typed language (like Pascal) did not have garbage collection and that allocated memory had to be explicitly released. If a dangling pointer existed that still pointed to the old memory location, it is possible that a new data structure can get allocated in the same space with the slot the dangling pointer refers to now pointing to a different type. For example, if the pointer initially pointed to an integer, but in the new space another pointer took its place, then that pointer could be changed to anything simply by changing the value of the integer. Because it is not specified what would happen when such a pointer is changed, the language is not type-safe. Note that garbage collectors are best implemented in languages that allow pointer arithmetic, so that the library that implements the collector itself is best done in a type-unsafe language like C.

See also

Further reading

 

<< PreviousWord BrowserNext >>
obliq
caucasian avars
wet and messy fetishism
venus envy (comic strip)
edmund gurney
maultasche
list of valleys in india
point (topology)
pasha wahba yusuf
wbre tv
list of mountains in india
quaternary sector of industry
arginase
philip dormer stanhope, 4th earl of chesterfield
archway tube station
cinema of quebec
jakob nielsen
jeanne marie langtry malcolm
list of rivers in india
will shortz
north east india
new world order (political)
new world order (conspiracy)
robin hood daffy
rann of kutch
list of indian districts
gamesurge
she is suffering
karl robert eduard von hartmann
arthur russell (cellist)
history of baseball
birds of prey
origins of baseball
extraterrestrial skies
ingvar
history of rail transport in ireland
lanark highlands, ontario
karl christian friedrich krause
baker brook, new brunswick
japanese saw
imago
gainesville college
savatage
oracle (comics)