neitzel@infbs.UUCP (06/30/87)
How would you implement generic functions/data types in C ? Has someone already written some helpful packages going in such a direction ? Martin Neitzel ...!mcvax!unido!infbs!neitzel /**** Skip the rest, if you aren't interested in this topic ****/ I mean something to the effect of: #include "generic_stack.h" #define STACKTYPE StackOfFoobar #define STACK_ELEMTYPE struct foobar * generic_fn_create_stack ( new_foobar_stack ) generic_fn_pop (pop_one_foobar) ... main() { StackOfFoobar first_stack; first_stack = new_foobar_stack(); ... I for one have a such a model working, it even supports conditional generation of "foo_stack.h" vs. "foo_stack.c". The aim of this note is to stir up some discussion about such concepts. Sorry, if this repeats older stuff... I think ADA's (ok ok...: (tm)DoD) GENERICS are not too difficult to imitate. Maybe you can only achieve a subset of all its facilities, but that wouldn't hurt too much. I know that standard UNIX (yet another (tm)) tools like "m4", "sed" and "awk" would fit better to this task, but please TRY at least one approach with the mere C-preprocessor. However, any contributions are welcome. Last not least: I'm interested in generics generating "source level code", that is (quite) strongly typed. In other words, I don't mean "general" library routines like "malloc()" or "tsearch()".