🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Can you nest subroutines in C?

#305
From: Mike (I'll think of something ye...
Date: Sun, 02 Jul 1989 18:41
69 lines
2886 bytes
In article <4525@crash.cts.com> wade@pnet01.cts.com (Wade Bickel) writes:
<mwm@eris.berkeley.edu (Mike (I'll think of something yet) writes:
<>You're not looking very hard. Please translate the following C
<>construct into M2:
<>
<>	short main[] = {1, 2, 3} ;
<>
<
<Sure,
<
<        main : ARRAY[0..2] OF INTEGER;
<
<        main[0] := 1; main[1] := 2; main[3] := 3;
<
<>On hardware that supports it, this sets up three words, puts the
<>values 1, 2 and 3 into them, and arranges to branch to that location
<>under the right conditions.
<
<        I don't see how the code you've listed arranges the branch, so perhaps
<I am missing something, but since I understand the code you've listed, I think
<it unlikely.

Yes, you're missing something. "main" is always the first symbol run
in any C program (well, normally, anyway - some implementations allow
you to avoid it, but all should invoke main above if the hardware
supports it). I was thinking of a specific program, and chose a bad
example. Better would be:

	int funcy[] = {1, 2, 3} ;
	.
	.
	.

	x = ((int *())funcy)() ;

And the intialization is sort of immaterial. It's the ability to call
your data that's important here.

<        Yes, M2 can be used to generate and deal with address exceptions.  The
<new Benchmark debbugger does so.

And it's written entirely in M2? Care to show the M2 to generate an
address exception? The C is simple (and once again, makes assumptions
about the hardware it's running on):

	int *y ;
	char x[2] ;

	y = (int *) &x[0] ;
	*y = 1 ;
	y = (int *) &x[1] ;
	*y = 1 ;

BTW, I also sent you mail giving the the real reason that C doesn't
have nested subroutines. Not having recieved a reply, I'm assuming the
mail isn't getting through, so I'll repeat it.

C doesn't support nested subroutines because they require code
expansion into something other than simple sequences of PDP-11 code.
You can dress it up and say "it violates C's being close to the
machine", but that's only true for certain classes of machine. The
PDP-11 is an example of same, and the first target for a C compiler.

	<mike
--
It's been a hard day's night,				Mike Meyer
And I been working like a dog.				mwm@berkeley.edu
It's been a hard day's night,				ucbvax!mwm
I should be sleeping like a log.			mwm@ucbjade.BITNET
Technical Details
Message-ID: <25964@agate.BERKELEY.EDU>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!ucbvax!agate!eris.berkeley.edu!mwm
References: <4525@crash.cts.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!ucbvax!agate!eris.berkeley.edu!mwm
From: mwm@eris.berkeley.edu (Mike (I'll think of something yet) Meyer)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Can you nest subroutines in C?
Message-ID: <25964@agate.BERKELEY.EDU>
Date: 2 Jul 89 18:41:28 GMT
References: <4525@crash.cts.com>
Sender: usenet@agate.BERKELEY.EDU
Reply-To: mwm@eris.berkeley.edu (Mike (I'll think of something yet) Meyer)
Organization: Missionaria Phonibalonica
Lines: 69