Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] compiler question

0 views
Skip to first unread message

Michael Wohlwend

unread,
Jul 22, 2006, 3:22:00 PM7/22/06
to caml...@inria.fr
Hi,

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
try
while true do
a0.(!idx) <-get32 file;
incr idx;
done
with
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 ? :-)
cheers,
Michael

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Richard Jones

unread,
Jul 23, 2006, 4:00:59 AM7/23/06
to Michael Wohlwend, caml...@inria.fr
On Sat, Jul 22, 2006 at 09:19:15PM +0200, Michael Wohlwend wrote:
> let idx = ref 0 in
> try
> while true do
> a0.(!idx) <-get32 file;

You shouldn't rely on the order that these are executed. Normal
parameter evaluation (which this is not) in OCaml happens to be right
to left, but it's not defined to be that way. Use the let binding if
you depend on a particular ordering.

> let t = get32 file in
> a0.(!idx) <- t;

Rich.

--
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com

0 new messages