[comp.lang.c] Implementation of global constructors

dave@dvm.UUCP (David Brand) (04/09/87)

I am looking for a more general way to initialize global variables in C.
Specifically, I need to initialize a global variable declared in an arbitrary
file (i.e. not necessarily the one which defines main) to the value returned
by a function.  I realize that there are many ways to handle this in specific
cases; but, I am looking for something more general.

I understand that C++ is implemented as a preprocessor which produces C.  Since
a global constructor requires precisely this facility I suppose that a
description of how this works is really what I'm after.

I realize that this could be implemented with COFF by allocating an
initialization segment and executing it before main.  An initialization segment
could also be fudged under BSD.  Does anyone have any specific information
on how C++ creates such segments using standard C?

I am looking for specific responses.  C code fragments would be useful.

Please respond via email.  If there is sufficient interest, I will post a
summary...

-- 

					- Dave

...seismo!cmcl2!phri!orville!dvm!dave
		     -------