encore icon indicating copy to clipboard operation
encore copied to clipboard

dividing by 0 results inconsistent depending on C implementation

Open helanhalvan opened this issue 8 years ago • 3 comments

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.

helanhalvan avatar Sep 27 '16 08:09 helanhalvan

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.

albertnetymk avatar Sep 27 '16 08:09 albertnetymk

One could argue that it should be fixed at the Encore level and not relegated to the C compiler.

supercooldave avatar Sep 27 '16 09:09 supercooldave

Revisit after exceptions go mainline.

supercooldave avatar May 04 '17 08:05 supercooldave