Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ucbvax!bloom-beacon!WSL.DEC.COM!haynes From: haynes@WSL.DEC.COM Newsgroups: comp.windows.x Subject: Re: Automatic module initialization (was Xtk Resource Converters) Message-ID: <8805260205.AA26633@gilroy.dec.com> Date: 26 May 88 02:05:30 GMT Sender: daemon@bloom-beacon.MIT.EDU Organization: The Internet Lines: 41 > >This is one of the reasons I hate C. In a reasonable language you would > >have module initialization happen automatically at program startup. > >Since C doesn't do this, you have to do your own initialization > >MANUALLY. > > [...] So I'm afraid you're stuck with > >either initializing all of your classes manually, and registering the > >type converter in the class initialization code, or providing an > >explicit intializer for your stuff, and requiring your clients to call it. > > Nonsense. It is VERY EASY to write a module that does first time > initialization in C. It adds maybe 10 lines of code to the module. > There is no reason to either (A) require your clients to call an > explicit initializer, or (B) initialize any class before a client > wants to use it. To wit: Nonsense yourself. Go back and read the original statement of the problem. The problem is that you want to define your own resource type converter, and have it automatically registered. You could do it by registering the type converter in the class_initialize proc of some class that uses the new resource type (as Ray Hill, the original poster, points out) but that may be too late, since you may want to pass one of these things in the arglist to the create call for creating the first widget of that class. This is before the class is initialized. The convert proc (via XtConvert) may be the only way of getting resources of the required type, or may simply be the most convenient method. A reasonable language would provide automatic static intialization sections for exporting modules. This initialization section would get called by the initialization section of any module importing something from the exporting module. Some care must be taken to deal with the inevitable initialization cycles that recursive dependencies cause. This is effectively requiring the compiler to do the bookeeping that your example does explicitly. Of course C, lacking the notion of a module, or exports, or imports, can't provide the needed support; leaving it to the programmer. We have attempted in the toolkit to do some of this for you, with static class initialization. We can't do it all, as much as we would like to. -- Charles [If else anyone wants to debate the merits of C as a modern programming language, I suggest that they, and I, do it somewhere other than "xpert/comp.windows.x".]