Marian said:
There are at least two counterexamples in last two days on
this forum. There are two threads asking for such library in C.
Why they do not simply switch to C++ at this stage of development?
It is probably not as easy as this. C an C++ are two different
languages.
Yes, but paradoxically, this is the wrong newsgroup to discuss
something like a "standard generic library for C". There simply is no
audience for your ideas here. People may come here periodically with
such questions, but the loiterers here are more interested in the
standard of C than the practice of C. You'll notice you got a lot of
arrows slung at you, but not a lot of useful feedback.
There is a sentiment amonst some programmers that the only real value
of C++ is, in fact, STL. But as you correctly point out, C++ also
introduces many semantic language differences from C that may prevent
it from being adopted (not the least of which being that the C++
standard is something like 10 times larger) by programmers for various
reasons.
So the obvious conclusion is that if a good enough library of generics
(whether via macros, or whatever mechanism) were made available that,
there would be amongst those programmers I just referred to who would
probably be very interested in them. Then of course there are people
like me, who just sees the value of generics in general.
Ok, but that isn't exactly what you've provided. Instead, you've taken
a position that you will never dynamically allocate any memory or
create/declare your own fresh data structures. And what you are really
supplying is a set of algorithms which can be applied to data
structures that are user generated. That's fine, and an interesting
take on the problem, but then what you are doing is not exactly
comparable to what STL does.
For example, the primary value of STL that *I* personally saw, is the
inclusion of the vector<> template. A vector is like a dynamically
sized array -- it can be indexed directly, trivially iterated, sorted,
rotated, etc. Since you restrict yourself from use of malloc(), your
library doesn't implement any container abtraction for things such as
vectors or deques, etc -- you require an array based implementation by
the user, if you want to sort it, for example.
So in the end you will find yourself restricted, and certainly not able
to duplicate the entire functionality of STL. Your hash table, for
example, implements only the chaining-style hash tables, which are
generally somewhat slower than the open-address style.
I would also posit, that one of the main problems in C programming, is
that memory/buffer management is a common place for errors, many of
which have become quite famous bugs.
So I guess I would wonder if you would be willing to consider,
possibly, adding perhaps a "level 2 API" for building real ADT which
include their own memory management? That, I think, is where the real
holy grail for this kind of mechanism for C is.
But in generally, I highly endorse your mechanism for implementation.
Where C is very weak in many ways, one of its bizarre strengths is the
source-level macro concatenation feature. And its an interestingly
natural way of trying to implement generic programming in C.