Path: utzoo!attcan!uunet!lll-winken!ames!hc!pprg.unm.edu!unmvax!ncar!boulder!sunybcs!rutgers!bellcore!texbell!uhnix1!nuchat!sugar!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.lang.misc Subject: Re: Call by string (was: B&D) Message-ID: <2863@ficc.uu.net> Date: 24 Jan 89 14:53:21 GMT References: <4261@enea.se> Organization: Xenix Support Lines: 63 In article <4261@enea.se>, sommar@enea.se (Erland Sommarskog) writes: > But Peter's function tables? Could one not require that every > function loads a table entry at startup with itself? The global access > cannot be a problem. Unfortunately, there is a little obstacle. > To do the loading the module has to be activated. But by whom? The > menu handler does at this stage not know about it. So you have to > have some other code that knows about all functions in the system, > and this is exactly what we want to avoid. Well, there are a number of objections to this argument. First of all, not all functions are suitable for use in a menu... even in a language like Forth. Lisp, where each routine effectively validates all its arguments at run time might be able to get away with this, but the overhead seems a little high. The programmer knows which functions do make sense, and can stick them in the table. Secondly, some languages (Modula, for example) do have an initialisation section for each module. Stick them here. Finally, have you never heard of a preprocessor? Put this in your code: function(args) /* %id "name" */ ... Then run the following script from your makefile: sed -n '/%id/s/\(.*\)(.*%id \(".*"\).*/ \2, \1,/' *.c > functab.i And finally: functab.c: struct { char *name; int (*func)(); } functab { #include "functab.i" }; ... > So in what langauge can you implement the calling-part of this menu > handler without calling some OS function? (It will be interesting to > see what ideas that turn up this time.) If you really want to be sick, you can do this: call.h: struct fentry { char tag[4], *name; int (*func)(); }; #include "call.h" struct fentry foobar_entry = { "%id", "foobar", foobar }; And then do a linear search through memory for the unique tag string at startup time. Gross, wot? I got the inspiration for this from some guy's 'C' garbage collection code. -- Peter da Silva, Xenix Support, Ferranti International Controls Corporation. Work: uunet.uu.net!ficc!peter, peter@ficc.uu.net, +1 713 274 5180. `-_-' Home: bigtex!texbell!sugar!peter, peter@sugar.uu.net. 'U` Opinions may not represent the policies of FICC or the Xenix Support group.