Path: 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 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.