From: Jim Weirich Date: 2003-02-16T15:14:02+09:00 Subject: Re: von Rossum on Strong vs. Weak Typing On Sat, 2003-02-15 at 23:44, Paul Brannan wrote: > On Sat, Feb 15, 2003 at 02:35:08PM +0900, Ryan Pavlik wrote: > > Consider that a char is just 1 byte, and while there's pretty syntax: > > > > char a = 'A' > > > > there's no difference between that and > > > > char a = 65 > > Both 'A' and 65 are literals with type int. You haven't shown that C is > typeless; only that 'A' and 65 have the same type, and that this type > can be implicitly converted to a char. > > > Bringing this back on topic, C is statically typed, which gives the > > compiler the ability to do some nice optimizations, but results in > > weaker typing, too (at least by matz's definition). > > Static typing does not result in weak typing. C++, Java, and OCaml are > examples of languages that have strong static typing. C's weak typing > is the result of being able to implicitly convert from almost any type > to almost any other type (or as matz says, the type "can be mixed and > changed very easily"). Actually, I would say C is weakly typed because it is easy to accidently interpret data as the wrong type ... especially in pre-ANSI C (without prototypes). For example ... One file contains ... extern int f(); int main () { f(3.1416); } In another file ... int f(x) int x; { ... } Unions are also problematic, although in that case you expect problems so accidents are less likely. -- -- Jim Weirich jweirich@one.net http://w3.one.net/~jweirich --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)