Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!unido!infbs!neitzel From: neitzel@infbs.UUCP Newsgroups: comp.lang.c Subject: generics for 'C' - (nf) Message-ID: <19000001@infbs.UUCP> Date: Tue, 30-Jun-87 09:22:00 EDT Article-I.D.: infbs.19000001 Posted: Tue Jun 30 09:22:00 1987 Date-Received: Fri, 3-Jul-87 05:12:32 EDT Lines: 49 Nf-ID: #N:infbs:19000001:000:1377 Nf-From: infbs!neitzel Jun 30 14:22:00 1987 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()".