Posted May 14, 2018
dtgreene: Another problem would be the following (and I think this might affect JavaScript, but I am not sure):
int func(int x)
{
if (x = 0) {
puts("No, I will *not* divide by zero; you can't make me.");
abort();
} else {
return 60 / x;
}
}
Alaric.us: JS has has both positive and negative Infinity, so division by zero is allowed. Take a look at the screenshot. int func(int x)
{
if (x = 0) {
puts("No, I will *not* divide by zero; you can't make me.");
abort();
} else {
return 60 / x;
}
}
(Rust fixes this issue by having the assignment return (), and by having if statements require boolean values, so the code fails to compile.)
(Python fixes this by not allowing assignments in the middle of expressions; trying to compile the corresponding code will give you a syntax error.)