On Thu, 11 Sep 2008, Jason Melbye wrote: > > I'm not sure I completely follow the bit about creating a closure and > > computing later. But I think I see how to do this now (or at least one way > > to do this.) Rather than have my C functions that I wish to call of the > > form fnct(arg1, arg2, ..., argn) where n is variable, I could just have them > > all of the form fnct(int argc, param_list *params), kind of like how main > > works. I could keep some information about them like how many and what > > types of parameters they take and do a little checking before invoking them > > to make sure I have a proper set of parameters.
You don't even need to do that. You could have them of the form int (or some other return value) fnct(void* v); and cast `v' to the appropriate type (pointer to `x', pointer to `y', etc.) in the function. If the function takes a variable number of arguments, the argument could be a struct containing a pointer to the next element in a linked list, with 0 (or NULL, if you prefer) as the last element. For example: struct foo { int some_int; /* or whatever */ float some_float; struct foo* next; } `next' should be initialized to 0. This sort of thing is slightly easier in C++, where you can define a constructor and you don't have to type `struct' everywhere. Of course, you can pass the number of arguments as a separate argument if you want to. And checking for errors is always good (unless you check so much that your program never gets around to doing any useful work). Laurence Finston _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison