[comp.archives] [comp.lang.c] Re: strings as functions

peterf@caroli.csis.dit.csiro.au (Peter A Fletcher) (01/10/91)

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.663214690@godzilla> 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