|
|
|
|
|
by kazinator
3233 days ago
|
|
There is also the related aspect of conversions. Ada is said to be stronger than C even if we ignore the "holes in the type system" of C because it doesn't allow implicit conversions (conversions without an explicit conversion operator or casting syntax). Though C won't treat a "3.14" character string as a number, it implicitly converts among numbers of different kinds, and converts between void * and object pointers. Narrowing conversions silently discard data ("implementation-defined result"), and so do conversions between same size but different signedness. Out-of range conversions between integer and floating-point values can trigger undefined behavior. (These issues are still there when the conversions are explicit, but when the conversion are implicit, the issues can sneak into the code more easily by accident). Though Lisp was listed in the grandparent posting as "strongly typed", it also has something similar to C's implicit conversions: [1]> (sin 42)
-0.91652155
[2]> (sin 42.0)
-0.91652155
[3]> (+ 1 2.0)
3.0
Unlike C, it won't go from floating to integer: [4]> (evenp 3.0)
*** - EVENP: 3.0 is not an integer
Whereas if we had an bool evenp(int arg);
function in C and called it as evenp(3.0);
or even evenp(3.1);
it would work. |
|