joefritz@pawl12.pawl.rpi.edu (Jochen M. Fritz) (07/18/90)
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@pawl.rpi.edu | wage war as the world does.-- 2 Cor. 10:3 | | usergk2s@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 | ------------------------------------------------------------------------
henry@zoo.toronto.edu (Henry Spencer) (07/18/90)
In article <!_X$`+#@rpi.edu> joefritz@pawl12.pawl.rpi.edu (Jochen M. Fritz) writes: >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? You cannot do this portably in C; there are an increasing number of compilers which cannot do it at all, because calling conventions differ depending on the details of the parameters. -- NFS: all the nice semantics of MSDOS, | Henry Spencer at U of Toronto Zoology and its performance and security too. | henry@zoo.toronto.edu utzoo!henry