encore
encore copied to clipboard
dividing by 0 results inconsistent depending on C implementation
This code
class Main {
def main() : void {
let x = 1/0;
print("bad");
}
}
Will have different results based on what C implementation used. On mine it prints bad, for some people it causes a crash. What encore want to do I don't know, but it's inconsistent.
int main()
{
int x = 1/0;
puts("done");
return 0;
}
$ clang-3.8 -fsanitize=undefined -fno-sanitize-recover=all hello.c && ./a.out ; echo $?
hello.c:12:12: warning: division by zero is undefined [-Wdivision-by-zero]
int x = 1/0;
^~
1 warning generated.
hello.c:12:12: runtime error: division by zero
1
My gcc-6
works similarly, but gcc-4.8
doesn't recognize those sanitize options. Fixing it this way will "kind of" require users to upgrade gcc or clang.
One could argue that it should be fixed at the Encore level and not relegated to the C compiler.
Revisit after exceptions go mainline.