From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=SPF_SOFTFAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id B0134BC54 for ; Sun, 14 Jun 2009 23:08:29 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnUCAMwDNUrUGyoGlGdsb2JhbACBT5Z3AQEBAQkLCAkTA7dEhA0F X-IronPort-AV: E=Sophos;i="4.42,218,1243807200"; d="scan'208";a="28054576" Received: from smtp6-g21.free.fr ([212.27.42.6]) by mail2-smtp-roc.national.inria.fr with ESMTP; 14 Jun 2009 23:08:28 +0200 Received: from smtp6-g21.free.fr (localhost [127.0.0.1]) by smtp6-g21.free.fr (Postfix) with ESMTP id A1950E080C9; Sun, 14 Jun 2009 23:08:23 +0200 (CEST) Received: from macbookpro.local (lns-bzn-48f-81-56-220-129.adsl.proxad.net [81.56.220.129]) by smtp6-g21.free.fr (Postfix) with ESMTP id 7BC77E08137; Sun, 14 Jun 2009 23:08:20 +0200 (CEST) Message-ID: <4A3567B6.4030002@univ-savoie.fr> Date: Sun, 14 Jun 2009 23:12:22 +0200 From: Christophe Raffalli User-Agent: Thunderbird 2.0.0.21 (Macintosh/20090302) MIME-Version: 1.0 To: Jon Harrop Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] evaluation order References: <4A352717.7020909@univ-savoie.fr> <200906142040.47645.jon@ffconsultancy.com> In-Reply-To: <200906142040.47645.jon@ffconsultancy.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; christophe:01 raffalli:01 raffalli:01 univ-savoie:01 christophe:01 ocaml-:01 bytecode:01 nativecode:01 decr:01 ocamlc:01 ocamlopt:01 bug:01 ocaml:01 unspecified:01 ocaml's:01 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 ... Cheers, Christophe