Re: [SLUG] [PIG] call a function without knowing its name in C

From: Eben King (eben1@tampabay.rr.com)
Date: Sun May 28 2006 - 02:22:56 EDT


On Sun, 28 May 2006, Sick Twist wrote:

> I'm writing a little project in C and have hit a wall. Let's say I have
> Functions A, B, C, & D. How can I make A dynamically call B, C or D based on
> a keyword in a text file *without* A knowing the exact names of functions B,
> C or D beforehand?
>
> Is there some trick I can do with #define, enum and function pointers? Or
> perhaps some other way to go about it? The goal is to make it easy to add new
> functions to the program without having to continually modify all the
> functions that might call them.
>
> Perhaps I am overly complicating things with abstraction but I am still
> curious to see if it can be done.

In some course I took in the last year or two, the professor briefly covered
functions as arguments to a function. That sounds like it'll do what you
want. But darned if I can find the notes. And I'll try to be more vague in
the future. :-) But maybe that gives you a pointer.

-- 
-eben    ebQenW1@EtaRmpTabYayU.rIr.OcoPm    home.tampabay.rr.com/hactar
TAURUS:  You will never find true happiness - what you gonna
do, cry about it?  The stars predict tomorrow you'll wake up,
do a bunch of stuff and then go back to sleep.  -- Weird Al
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:26:34 EDT