5 ms·
#include "pretty.h" void print_int(int value){ println(value); } int main (int argc, string argv[]) { long value = 23849234723
by byroot 2y ago
#include "pretty.h"
void print_int(int value){
println(value);
}
int main (int argc, string argv[])
{
long value = 23849234723748234;
print_int(value);
}
How is this strongly typed?
$ cc test.c -o test && ./test
-1411401334
And to be clear, weak vs strong isn't a boolean property but a spectrum, but would be hard to argue with a straight face than C is a strongly typed language.
- brabel 2y agoC is likely the only example of a programming language that is clearly statically typed while at the same time being weakly typed. For a reason: as your example shows, it's a really bad idea (but understandable for a language from the 60's).
- layer8 2y agoC is from the 1970s. Java is weakly typed in its generics, despite being statically typed. I’m sure there are more examples.
- deleted 2y ago[deleted]
- brabel 2y agoI don't think Java is weakly type even in generics. You can't "fake" your way with types like in C, you need to explicitly cast, which fails if you try to make an invalid type cast.
- smithza 2y agoThe more pedantic compiler flags you introduce, the more strongly typed it becomes.