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
compiler question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-07-22 (19:18)
From: Michael Wohlwend <micha-1@f...>
Subject: compiler question

I executed the following code,  the array a0 was allocated to match the 
filesize and get32 reads 4 bytes via input_byte:

  let idx = ref 0 in
    while true do
      a0.(!idx) <-get32 file;
      incr idx;
    End_of_file -> close_in file;

this code works as bytecode but gives an array exception when compiled to 
native code. Is the execution order different on the two compilers? The a0.
(!idx) get evaluted before the get32 in native-code, but with bytecode the 
get32 is computed first (it seems).
The code works if I add a temporary variable like:
let t = get32 file in
a0.(!idx) <- t;

is this a feature ? :-)