"Matt Fowles" <[EMAIL PROTECTED]>
> Were this C++ I would say that we could write a single general purpose
> stack and use template meta-programming to avoid the overhead.  Is there
> a similar solution available in C?
>
> My instincts tell me that this solution will be dirty to the tune of
> massive macroing, but perhaps someone better with pure C than I am could
> provide a better answer.

C does do templates, sort-of:

#define STACK_TYPE int
#define STACK_MAX_SIZE 1024
#include stack_template_decl.h
#include stack_template_impl.h
#undef STACK_TYPE
#undef STACK_MAX_SIZE

(often one instances the stack_decl in a header file, and the _impl in a .c
file.) I've also seen the calling convention where the template files do the
#undefs.

There can be some issues debugging this stuff though: gcc will give currect
line numbers, but will not tell you which instance of the stack template
you're in. So if a bug is only in, say, stacks of double: then this won't be
immediately apparent. On the plus side, the lack of type information means
that you don't get c++'s 8000-character error messages.


Dave.


Reply via email to