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-11-07 (08:23)
From: skaller <skaller@o...>
Subject: Re: [Caml-list] Int overflow in literals
On Mon, 2003-11-03 at 03:23, Brian Hurt wrote:
> On 3 Nov 2003, skaller wrote:
> > On Fri, 2003-10-31 at 08:14, Oleg Trott wrote:
> > > On Thursday 30 October 2003 03:05 pm, Issac Trotts wrote:
> > 
> > > 
> > > Or, better yet, use Big_int:
> > 
> > Felix does that, and i'm very happy with the idea.
> > Constant folding is done in "infinite" precision.
> > The check for size, if done, would occur in the backend
> > code generator .. not the parser.
> > 
> This is a bad idea.  I'd like the constant folding to be done in the word 
> length that the code will be executed in- this way, there is no difference 
> between code that is executed at run time and code that is executed at 
> compile time.

The results will be the same, so its a good idea :-)

The Felix types 'int', 'long' etc have the same sizes
as the corresponding C types. But the semantics are
NOT the same. Bitwise operations are not permitted,
and the result is undefined on overflow.

The Felix type 'int32' on the other hand is required
to be two's complement 32 bit, and allows overflow
as in C. Bitwise operations are not allowed.

The type 'uint32' allows bitwise operations.

The constant folder respects these semantics.
Actually only int type is folded .. and if the
result would overflow at run time then the behaviour
of the program is undefined, and so the well defined
result of constant folding is correct, since it is
an element of the set 'undefined' of all possible results :-)

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