Topic: initialization (was: Passing a class name as parameter)
Author: checker@acf5.NYU.EDU (checker)
Date: 20 Sep 92 22:06:32 GMT Raw View
jbuck@forney.berkeley.edu (Joe Buck) writes:
>Because real compilers call the constructors before main is called. If
>someone gave me one that didn't, I'd add a new startup module. If the ARM
>rule makes something impossible to implement, but I'm assigned to build it
>anyway, I'll manage somehow.
These sound like famous last words.
We've discussed this on BIX a number of times. As far as I can tell,
given a program that already compiles, links, and runs, there is no
standard way of simply linking in a new object module and affecting its
behaviour according to the ARM.
Chris
Author: jbuck@forney.berkeley.edu (Joe Buck)
Date: 21 Sep 1992 19:59:40 GMT Raw View
jbuck@forney.berkeley.edu (Joe Buck) writes:
>>Because real compilers call the constructors before main is called. If
>>someone gave me one that didn't, I'd add a new startup module. If the ARM
>>rule makes something impossible to implement, but I'm assigned to build it
>>anyway, I'll manage somehow.
In article <1922@acf5.NYU.EDU> checker@acf5.NYU.EDU (checker) writes:
>These sound like famous last words.
Not at all: leaving little problems like this hanging around is one way
to get hired back later as a consultant. :-)
>We've discussed this on BIX a number of times. As far as I can tell,
>given a program that already compiles, links, and runs, there is no
>standard way of simply linking in a new object module and affecting its
>behaviour according to the ARM.
Excuse me? Surely if you read my original article you realize that I
explained that a system-dependent module is added to do the incremental
linking? Of COURSE it's system-dependent; the ARM version of the language
provides no mechanism to do this, so one must be added. Given that you
need to do this, the correct way to proceed is to provide a
system-independent interface to the system-dependent mechanism. I don't
believe that the language should be extended to provide for incremental
linking. The only language standardization issue that may come up here is the
question of whether the rule for initialization of global and other
file-scope objects makes it impossible to implement the idea of using
constructors to register objects, as I have described. To the extent that
the ARM rule says you can't assume that the global objects are constructed
until some function in the file is called, there's a problem. It seems
inconsistent with the notion that a constructor can be used for its side
effects and therefore can't be optimized away, as is done here.
One way to satisfy the ARM requirement is to create a new function that
calls some dummy routine in each file with static constructors before main
is called -- this could always be done to make it work.
--
Joe Buck jbuck@ohm.berkeley.edu
Author: checker@acf5.NYU.EDU (checker)
Date: 22 Sep 92 21:37:00 GMT Raw View
jbuck@forney.berkeley.edu (Joe Buck) writes:
>One way to satisfy the ARM requirement is to create a new function that
>calls some dummy routine in each file with static constructors before main
>is called -- this could always be done to make it work.
This, or a variant on this, seems to be the only way to make it work.
Interestingly, the ARM says in the same (infamous) paragraph that any
function call or _use of an object_ in the compilation unit will assure
initialization. I don't have access to a compiler that doesn't do inits
before main, so I can't test that this is implemented in the real world,
though.
Chris