Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Int overflow in literals
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-10-31 (16:56)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Int overflow in literals
> I understand that int overflow is not checked on arithmetic for
> efficiency reasons, but IMHO it would be better if it was checked
> at least in literals. When someone writes 10000000000, he certainly
> does not mean -737418240.
> It caused confusion in a class when someone was interactively testing
> a function with larger and larger inputs.

This is a very good suggestion.  There are several ways to go about this:

- The lexer emits a warning in case of overflow, and proceeds with
  the value modulo the size of the type.
- The lexer emits an error on overflow.
- The int_of_string functions raise an exception on overflow.

Based on the comments posted so far on this list, and on a quick
discussion with colleagues, I'm inclined toward the third approach
(int_of_string fails in case of overflow).  Does anyone know of a use
scenario where this new behavior of int_of_string would be a problem?

- Xavier Leroy

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: