varargs -> normal parameters

Jochen M. Fritz joefritz at pawl12.pawl.rpi.edu
Wed Jul 18 05:42:54 AEST 1990


I want to write a function, that can call any other function.  The called
function and its parmeters are given as parameters so that it can be called.
The clintcher is since I want to be able to call anything how can I 
dereference the parameters to call the function?

for example:

void foo (void (*fn)(), ...)
  {
     (*fn) (...)         <- how can I do this line?
  }

void bar (int num, char ch)
  {
     printf ("%d %c",num, ch);
  }

main ()
  {
    foo (bar,12,'b');
  }

If there is a portable (ANSI) way to do this, that would be great, but if I 
have to resort to a machine dependant solution (ie pushing the stuff onto
the stack with inline assembly), I`d survive.  My compiler is Turbo C++,
but for now I'm sticking to just C, (I don't wamnt C++ code).  I do have
a 8086 assembler.

Any help would be appreciated.    Please no flames as to why I would want to
do this.  It would be the most elegant solution to my problem.

Thanx

 
------------------------------------------------------------------------
| Jochen Fritz            | For though we live in the world, we do not |
| joefritz at pawl.rpi.edu   | wage war as the world does.-- 2 Cor. 10:3  |      
| usergk2s at rpitsmts.bitnet| You have heard it said, Love your neighbor |
| Noah [the peace monger] | and hate your enemy.  But I tell you: Love |
|                         | your enemies.  Matt. 5:43-44               |
------------------------------------------------------------------------



More information about the Comp.lang.c mailing list