Jacques Garrigue <garri...@math.nagoya-u.ac.jp> writes: > From: Goswin von Brederlow <goswin-...@web.de> > >> I'm wondering if the execution order is defined during class >> construction. For example: >> >> let n = ref 0 >> let next () = incr n; !n >> class foo = object >> val x = next () >> val y = next () >> val z = next () >> method print = Printf.printf "%d %d %d\n" x y z >> end >> >> Will that always give x < y < z or could it initialize the values in >> different order? > > This is not explicitly specified in the manual (but not explicitly > left unspecified either). The same thing seems to be true for > initializers too.
Things like that should really be specified. In that regard the docs are saddly lacking. With a specified in order execution the following could even be allowed: class foo buffer = object val num = int_from_buffer buffer val data = Array.init num (float_from_buffer buffer) end > The current implementation keeps the definition order, and I don't see > why it should change, but if your code depends on such things it may > always be a good idea to put somewhere a bit of code that verifies > that the behaviour is correct. How would you verify that? If the order is unspecified then it might just give x < y < z in one case and x > y > z for a slightly different case where the compiler optimized differently. I would have to verify every single class where the order is important. > Jacques Garrigue MfG Goswin _______________________________________________ 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