Re: multi stack question/grumble

2003-06-30 Thread Benjamin Goldberg
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;}


Re: multi stack question/grumble

2003-06-27 Thread Dave Whipp
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.




Re: multi stack question/grumble

2003-06-27 Thread Leopold Toetsch
Dave Whipp [EMAIL PROTECTED] wrote:

 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

 There can be some issues debugging this stuff though:

And this is the big problem with it.

I think, we should have a general stack engine which just knows about
item size and chunk size. The base functions return a (void *) to an
entry.
The fast paths (now chunk add/del needed) could even be inlined. A
separate handling of the entries like in stacks.c could be on top of
this.

 Dave.

leo


multi stack question/grumble

2003-06-26 Thread Matt Fowles
Leopold Toetsch wrote:
( /me again mumbling why we have 6 different stack implementations with
a lot of duplicate code. One general stack with different sized data
items would do it too - with some overhead ;-)
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.

Matt