🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #6286

Re: Call by string (was: B&D)

#6286
From: Charles Bryant
Date: Wed, 08 Feb 1989 22:15
41 lines
1755 bytes
In article <1316@goofy.megatest.UUCP> djones@megatest.UUCP (Dave Jones) writes:
>From article <403@rpi.edu>, by jefu@pawl.rpi.edu (Jeffrey Putnam):
>... 
>
>The reason might be that the procedure you want to jump to was
>compiled after the main program was compiled, and was not, and could
>not be, known to the main program at the time of its compilation.
>...

Well here's another solution (which will work in many languages):

write your C code with function definitions like this:

char *			/* or whatever */
/*CALLABLE*/
func_foo(a, b, c)
{
 ...

Then write a small program (awk/sed script or whatever you like) to read a file
and take the first word of all lines following /*CALLABLE*/ and produce:

struct calltable {
	void (*func)();		/* whatever type you want */
	char *name;
} my_call_table = {
	func_foo, "func_foo",
	.
	.
	.
	};

Now write a function which takes a string, looks it up in the table and calls
it. By declaring the table 'extern', the program can be compiled, and the table
can be generated and linked later. The parts of the program you don't need
to be able to call can even be linked if your linker can produce one linkable
object from several.
-- 

		Charles Bryant.
Working at Datacode Electronics Ltd.
Technical Details
Message-ID: <523@maths.tcd.ie>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!ames!amdcad!sun!pitstop!sundc!seismo!uunet!mcvax!ukc!tcdcs!tcdmath!ch
References: <403@rpi.edu> <1316@goofy.megatest.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!ames!amdcad!sun!pitstop!sundc!seismo!uunet!mcvax!ukc!tcdcs!tcdmath!ch
From: ch@maths.tcd.ie (Charles Bryant)
Newsgroups: comp.lang.misc
Subject: Re: Call by string (was: B&D)
Summary: forget it
Message-ID: <523@maths.tcd.ie>
Date: 8 Feb 89 22:15:37 GMT
References: <403@rpi.edu> <1316@goofy.megatest.UUCP>
Reply-To: ch@maths.tcd.ie (Charles Bryant)
Organization: Maths Dept., Trinity College, Dublin
Lines: 41