>I fell in love with C, but strings stand between us. So I made this lib.

You and me both!

You'd like Pascal's strings, most notably those of Delphi/FreePascal -- the standard string type in those languages contains the length of the string before the pointer to the string (out-of-band signalling as opposed to in-band signalling as C's standard strings are, with a zero marking their end) -- much like your string implementation does.

Also, Delphi/FreePascal's strings -- contain a reference count, which is automatically updated when a whole string is copied from one string variable to another, and not freed until the reference count goes to zero.

The result is that Delphi/FreePascal's string copies, e.g.,

StringA := StringB;

Are lightning fast -- because only the pointer is being copied! (well, that and the ref count increased by one...)

If code later changes any value of StringB for any reason, then and only then is StringB copied and the value changed!

But anyway, getting back to strings in C, yes, I agree completely, there needs to be a better standard string type, so your idea is conceptually brilliant!

Now, as far as your code goes, I don't do that much C, so I can't really comment.

On the plus side, I've seen libraries in C that used far more code -- to accomplish far less!

On the "I'm not too sure about this" side (but then again, I don't do that much C, and other people can and will have other opinions) -- I'm not too sure about the use of macros which use other macros...

In other words, while this practice is certainly convenient, it can (and frequently does) lead to newer programmers not really understanding what the code does in those places...

Now, that's your call.

All I know is that if I was writing this for the maximum understanding by the programmer community, including new programmers, then my "rule of thumb" for that purpose would be "less macros" and "no nested macros"...

Things might be a little bit more difficult that way, but conceptually, what you're doing, at the highest level is simply this:

1) You're taking a series of bytes in memory.

2) You're wrapping this series of bytes in memory with various string handling functions, similar to, but not exactly the same as (because length is signaled before the string, etc.) the standard C ones, including functions to allocate/reallocate(resize)/copy and free that memory.

3) Net result of these modifications should be that C strings handled with these wrapper methods are more robust than regular C strings.

That, at its highest conceptual level, is all that's going on (or did I miss something?)

I know I could do all of that in one relatively terse source code file without most of the macros, and definitely without nested macros...

Of course, those are just my personal tastes as a programmer; but (as Harry and Paul so eloquently said!) "I am not the market" of all computer programmers, so it's quite possible that your coding style would both surprise and delight and make happy legions of other programmers who prefer that type of coding style!

In other words, take all that I say with the proverbial "grain of salt".

But, better C strings are sorely needed -- so a brilliant choice of area to work on!