[comp.lang.c] Initialization of Externals

andrew@teletron.UUCP (10/28/87)

In article <9897@brl-adm.ARPA> tom@vax1.acs.udel.EDU (Tom Uffner) writes:
>all externals and statics can be
>initialized "for free" to nearly anything desired at compile time,
>(cf. constant expressions) but an 'initialize()' proc would generate
>code and take time to execute.

Sometimes you have no choice..  (see below)

In article <6917@prls.UUCP>, gardner@prls.UUCP (Robert Gardner) writes:
> I prefer compile-time initialization when possible, but it's not
> necessarily "for free".

This is true when dealing with ROM-able code.  You are forced to write
explicit 'initialize()' procedures.

Our compiler (like most others) generates different segments for different
portions of code:
	.text - program instructions
	.data - initialized externals
	.bss -  uninitialized externals
We bind the .text and .data sections to ROM addresses and .bss sections to
RAM addresses at link time.  Thus, we are forced to allow initialized externals
for static data structures only.  Variable data must be initialized by an
'initialize()' routine called from the startup code.

I realize this is a digression from the original thread, and Tom's original
point about documentation of variable initialization is well taken, but one
can't always use compile-time initialization.

	Andrew

blarson@skat.usc.edu.UUCP (10/29/87)

In article <123@teletron.UUCP> andrew@teletron.UUCP (Andrew Scott) writes:
>In article <6917@prls.UUCP>, gardner@prls.UUCP (Robert Gardner) writes:
>> I prefer compile-time initialization when possible, but it's not
>> necessarily "for free".

>This is true when dealing with ROM-able code.  You are forced to write
>explicit 'initialize()' procedures.

I disagree.

>Our compiler (like most others) generates different segments for different
>portions of code:
>	.text - program instructions
>	.data - initialized externals
>	.bss -  uninitialized externals
>We bind the .text and .data sections to ROM addresses and .bss sections to
>RAM addresses at link time.  Thus, we are forced to allow initialized externals
>for static data structures only.  Variable data must be initialized by an
>'initialize()' routine called from the startup code.

On any compiler used to produce ROMable code, the copy should be part
of the startup code.  If your compiler wasn't designed for ROMable
code, you can probably refit it by re-writing the startup routine.
(the .data section must be allocated in both ROM and RAM.) The C
program does not have to be changed at all.  Examples of compilers
that (always!) produce ROMable, reentrant, position-idependant code
include all those sold by Microware for Os9/68k and Os9.
--

Bob Larson		Arpa: Blarson@Ecla.Usc.Edu
Uucp: {sdcrdcf,cit-vax}!oberon!skat!blarson		blarson@skat.usc.edu
Prime mailing list (requests):	info-prime-request%fns1@ecla.usc.edu