🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #320

Modula-2 and C initializations

#320
From: Kevin Klop
Date: Mon, 03 Jul 1989 06:19
57 lines
2189 bytes
BTW, the construct:

     int a[] = {1, 2, 3};

usually doesn't create any code (unless the intialization is allowed for
autovariables).  Instead it merely places the values into the initialized data
segment instead of zeros.

for instance, the above might generate the follwoing assembly code:

	section		BSS
	global	a

a:	db.w	1
	db.w	2
	db.w	3

whereas the equivalent M2 code:

	a	: array [0..2] of integer;

	a[0] := 1; a[1] := 2; a[2] := 3;

would generate something along the lines of:

	section	text

	movea	a7,a0
	adda	#6,a7
	moveq.w	#1,0(A0)
	moveq.w	#2,2(A0)
	moveq.w	#3,4(A0)

Note that this does not prove one superior over the other.  They are different,
and have different strengths and weaknesses.  In this particular case, 
C comes out as generating 6 bytes into the data segment, and M2 comes out
as generating 14 bytes into the code segment.  (If M2 doesn't allocate the
variable on the stack, then 2 bytes of code space are recovered).

To handle nested routines, the only "special" coding necessary is to keep track
of the current stack frame pointer.  This CAN be a pain in the neck, agreed,
as when accessing a variable one has to check backwards from the current stack
frame throught the next higher nesting level stack frame.  Yet, there ARE
advantages to it.

Ah well, I said that I didn't want to get involved in a "Language X is better
that language Y" discussion, and here I am starting to think about it. *grin*

                     -- Kevin --

Kevin Klop		{uunet|rutgers|amiga}!cbmvax!kevin
Commodore-Amiga, Inc.

The number, 111-111-1111 has been changed.  The new number is:
134-253-2452-243556-678893-3567875645434-4456789432576-385972

Disclaimer: _I_ don't know what I said, much less my employer.
Technical Details
Message-ID: <7203@cbmvax.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!cbmvax!kevin

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!cbmvax!kevin
From: kevin@cbmvax.UUCP (Kevin Klop)
Newsgroups: comp.sys.amiga.tech
Subject: Modula-2 and C initializations
Message-ID: <7203@cbmvax.UUCP>
Date: 3 Jul 89 06:19:05 GMT
Reply-To: kevin@cbmvax.UUCP (Kevin Klop)
Distribution: comp
Organization: Commodore Technology, West Chester, PA
Lines: 57