English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
evaluation order
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-06-14 (21:08)
From: Christophe Raffalli <raffalli@u...>
Subject: Re: [Caml-list] evaluation order
Jon Harrop a écrit :
> On Sunday 14 June 2009 17:36:39 Christophe Raffalli wrote:
>> Hello,
>> In OCaml-3.11.1 (I did not try other version),
>> the following code print 0 when compiled in bytecode and 1 in nativecode
>> for obvious reason of different evaluation order in the pair ...
>> let ptr = ref 0
>> let fn b =
>>   if b then incr ptr else decr ptr
>> let c = fn true, !ptr
>> let _ = print_int (snd c); print_newline ()
>> Is any difference between ocamlc and ocamlopt a bug ?
> Not at all, no. They are expected to have different behaviour with respect to 
> floating point arithmetic. In this case, they have chosen to evaluate 
> subexpressions in a different order, which is fine because the order of 
> evaluation is officially undefined.
Despite the fact that it should not be written in OCaml because the 
result rely on the unspecified evaluation order, my example still seems 
to contradict chapter 11 of OCaml's documentation:

"Compatibility with the bytecode compiler is extremely high: the same 
source code should run identically when compiled with ocamlc and ocamlopt."

This kind of bug could also be a nightmare to debug ... because the 
debugger is only available for bytecode ...