Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tut.cis.ohio-state.edu!ucbvax!VAX.ACS.OPEN.AC.UK!RW_GRIFFITHS From: RW_GRIFFITHS@VAX.ACS.OPEN.AC.UK Newsgroups: comp.lang.modula2 Subject: RE: Initialisation code: When is it called? Message-ID: Date: 29 Jan 91 11:39:04 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Modula2 List Organization: The Internet Lines: 26 The importation of a module causes the imported module to be initialized as the program (that imports the module) begins to execute. Since many different modules may be imported by many others (in a large program etc), it is necessary to give an ordering for the initialization. This order is the one in which they are textually listed in the import statement. The compilere works out the orderuing by examing the main program module first and then works backwards. IF there is a circularity in the initialization order ( ie two modules importing from each other) then strictly speaking the order is undefined; but most compilers can resolve this problem. For example TopSpeed M2 initializes in an order staring with the last module in the circular reference list, before repetitio n occurs. Eg. in the case of A importing B, B importing C and C importing A, the initialization order would be C, then B then A. However remember that this will not be portable to other compilers. Finally there is another rare case hen compilers can produce different initialization orders for the same program. This occurs when a module is imported into a definition module and then not used in the corresponding implementationmodule. In such cases some compilers do not initialize the imported module. Rob Griffiths The Open University