Newsgroups: comp.archives Path: utzoo!utgpu!news-server.csri.toronto.edu!ox.com!emv From: peterf@caroli.csis.dit.csiro.au (Peter A Fletcher) Subject: [comp.lang.c] Re: strings as functions Message-ID: <1991Jan10.041437.6375@ox.com> Followup-To: comp.lang.c Sender: emv@ox.com (Edward Vielmetti) Reply-To: peterf@caroli.csis.dit.csiro.au Organization: CSIRO Div of Inf Tech References: <1991Jan9.234327.4864@csis.dit.csiro.au> Date: Thu, 10 Jan 1991 04:14:37 GMT Approved: emv@ox.com (Edward Vielmetti) X-Original-Newsgroups: comp.lang.c Archive-name: gnu/utils/dld/1991-01-09 Archive: prep.ai.mit.edu:/pub/gnu/dld-3.2.1.tar.Z [18.71.0.38] Original-posting-by: peterf@caroli.csis.dit.csiro.au (Peter A Fletcher) Original-subject: Re: strings as functions Reposted-by: emv@ox.com (Edward Vielmetti) >In article mpapp@ (Mike Papper) writes: >>Is there a way to use a string value as the name of a function? >>In other words, can I use a string (possibly >>typed in by a programmer) as a function call to a function of >>the same name? There's a FSF product called 'dld' which allows you to do this plus a whole lot more. You can specify the name of a function as a string, and it will return the address of that function. It will also allow you to load and remove object files while your program is executing. Here is a sample test program using dld (included with the distribution) which does exactly what you ask: #include "dld.h" main (argc, argv) int argc; char *argv[]; { void (*func) (); (void) dld_init (argv[0]); printf ("Hello world from %s\n", argv[0]); func = (void (*) ()) dld_get_func ("printf"); (*func) ("Hello world from %s\n", argv[0]); } dld was written by Wilson Ho, and I think you can get it (under the terms of the FSF thing) from prep.ai.mit.edu. -peter. ------------------------------------------------------------------------------- Peter Fletcher, PhD student. Internet : peterf@csis.dit.csiro.au Phone : +61-6-2750914 Physical : CSIRO Division of Information Technology, ANU, Acton, Canberra ACT AUSTRALIA ------------------------------------------------------------------------------- -- ------------------------------------------------------------------------------- Peter Fletcher, PhD student. Internet : peterf@csis.dit.csiro.au Phone : +61-6-2750914