4 ms·
Can you name a language besides C++ and C in which comparing a signed integer to an unsigned integer will compile and run without warning while implicitly conve
by MichaelSalib 13y ago
Can you name a language besides C++ and C in which comparing a signed integer to an unsigned integer will compile and run without warning while implicitly converting one to the other?
- bcoates 13y agoAny weakly typed language like Forth is likely to have this behavior.
- aryastark 13y agoPascal? Is this a trick question? How many languages have the concept of "unsigned"? Lots of languages do implicit conversion. A few, coughJavaScriptcough coughPHPcough do some really stupid coercions.
- cbsmith 13y agoYou remember Fortran's old issue about float's vs. ints and variable names? Seriously, if you have languages with signed & unsigned types, and implicit conversion between the two, this can happen. In languages that don't have these features, it can't. However, almost all of them ALSO have ways that poorly written code works until it doesn't. It's a phenomenon very reminiscent of the halting problem.
- jkrems 13y agoWith reasonable compile options (e.g. -wall), it is issuing a warning. Every compiler config I used out-of-the-box via some IDE will show that warning. It's bad defaults of the compiler maybe, but hardly the fault of the language itself. Any beginners tutorial has to contain the compile and/or run command, no matter which language. At least C++ has unsigned types. Java doesn't even warn about `new int[-30]` and similar fun stuff (at least not generally).
- norswap 13y agoYou're not asking the right question. Most language don't make a distinction between signed and unsigned integer to begin with. And the error being showcased has nothing to do with weird conversions or over/underflows either.