Fix initialization order problem in generated code

review by @szeiger

(superseeds #676)