(argh, posting again, since a bunch of the damned angle brackets messed up :)
Well, that's kinda crappy, since then it becomes VERY memory-leak prone. What I'd rather see than that would be everyone switching to C++ and using the STL string class. It buys you a LOT, such as:
Plus a lot of other stuff. Yeah, badly-written C++ can perform really poorly, but if its features are used responsibly, it can become VERY powerful without much speed hit. For example, the scenegraph in Solace is stored as an n-ary tree where each hierarchal node keys its children by its name, making complicated scenegraph operations very simple, rather than the traditional mechanism of storing the name within the node and requiring the programmer to search through each child for the proper named node. As a result, name lookups are O(lg n) instead of O(n) (map uses a btree by definition, and the common SGI implementation specifically uses a red-black tree), while traversals still take only O(n). In practice, they perform about the same (actually, the traditional way's probably a little faster due to the overhead of a red-black tree), but it makes the programming a WHOLE lot easier.
- Being treated as a fundamental (passed by value unless explicitly by reference, etc.), making complex containment and the like very simple (map<string, string> gives you a PERL-style array, btw :)
- Not being limited to 8-bit char (very nice for i18n)
- Has an explicit size rather than being null-terminated (makes some string-processing operations a LOT faster while not slowing others down)
- Simple mathematical operations (operator+ instead of strcat, for example)
- Easily linked to the C++ IO streams stuff, making tokenization et al real easy (strstream::operator<< and so forth)
Similarly, it made programming my Markov chain ramble generator very simple. Rather than it being several source files with all sorts of containers and reimplementation and such, it's about 130 lines of C++, since a map<string, map<string, int> > does most of the real work. :) (This maps the first word to a mapping between second words and their chained frequency. I use another map<string, bool> to indicate whether a word can end a sentence.)
Anyway... what I'm trying to say is if you're going to completely change the semantics of libc strings to make them act like C++ STL strings except without the automatic cleanup, you'd might as well just have everyone switch to C++ and make it easier on themselves.
"Is not a quine" is not a quine.
I have a master's degree in science!
[ Hug Your Trikuare ]
[ Parent ]