Dave Whipp wrote:
> Matt Fowles
>> 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.

Any chance that this could be fixed with a #line pragma, with a filename
which is generated from the parameters?  E.g., something like:

   #define STRINGIFY(X) ??? /* make a string literal from a token */
   #define STACK_TYPE_STR STRINGIFY(STACK_TYPE)
   #define STACK_SIZE_STR STRINGIFY(STACK_MAX_SIZE)
   #define GENFILENAME \
      __LINE__ "[" STACK_TYPE_STR "x" STACK_SIZE_STR "]"
   #line 0 GENFILENAME

> On the plus side, the lack of type information means that you don't
> get c++'s 8000-character error messages.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "[EMAIL PROTECTED]
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}

Reply via email to