There are red flags in some of the function signatures that the author doesn't understand C.<p>For example functions that I guess are meant to be generic arrays that take int*. You could write volumes on how to approach generic arrays in C but this is certainly not one of them.<p>Also the use of "c standard library" is weird here. Any C programmer reading this phrase assumes a reasonably standard conformant libc. This is a bunch of interfaces the author made up.<p>Sorry for being negative but this doesn't pass a "production quality c code" at-a-distance sniff test.
Pretty good work so far. Some nitpicks…<p>The library uses malloc rather liberally, but rarely (if, ever) checks the result. Allocation functions failing to allocate is a recoverable state¹.<p>In addition to this, the library does not provide a builtin mechanism to override malloc from the stdlib. Freestanding targets exist! Also, on hosted targets, who isn't using aligned_alloc in at least some places nowadays?<p>Having to do the following song & dance sucks.<p><pre><code> #define malloc xmalloc
#include <yourthing.h>
#undef malloc
</code></pre>
[1] <i>I'd wager most C programmers today write programs in C to exercise as much control (maximal determinism?) as possible without having to write in *-Assembly. Yes, I'm aware that its abstract model of computation and semantic complexity make it anything but "low-level", but C can get rather close on some architectures with some compilers.</i>
Fine looking general helper functions, but I find it a bit confusing to call this a "standard library". That has a particular meaning in C/C++ already.
It's not a "standard" library though...<p>It's a nice "toolbox", but definitely not "standard" (word which has a very specific definition).
This is cute, and probably useful for hobby projects. If I may, it would be nice to have slightly more generic versions of some of the interfaces, and perhaps consider dropping "maximally" efficient from your tagline. Not only is it cleaner, you are less likely to get yelled at by people who focus on code like this:<p><pre><code> /* Function to concatenate multiple strings into a new string */
static inline char *concatenate(const char *str1, const char *str2)
{
size_t len1 = strlen(str1);
size_t len2 = strlen(str2);
char *result = (char *)malloc(len1 + len2 + 1);
strcpy(result, str1);
strcat(result, str2);
return result;
}</code></pre>
Thank you for this.<p>I really enjoy C (I'm a beginner).<p>Segmentation fault.<p>I should probably be using Rust. I really like how C maps to the machine and I find the semantics simple to understand compared to type systems.<p>The semantics of this library and lodash and other functional JavaScript patterns could probably be mapped to something that resembles a database query engine for general data structure traversal. Then the computer can work out how to allocate memory and what traversals are faster. And what traversals or queries are equivalent, a bit like Prolog. Every program is a compiler :-)<p>The boilerplate in C such as hashmaps, async, event loops, libuv, visitor pattern, indirection and so on I haven't yet wrestled with much yet.
Some observations:<p>1. Who owns the memory? How is the memory freed?<p>2. C doesn't have a lambda syntax, so using functional idioms like map, etc is a bit more boilerplate.<p>3. Lack of generics is painful (print_ushort_array, print_double_array, print_ulong_array, print_long_long_array)
Oh, I like this!!<p>I might need to look deeper but how is memory management done?<p>It seems like there’s some allocation happening on the background? For example, the split() or string_to_json(), some memory is happening somewhere.<p>I ask for more than curiosity, I wonder if this could be used in embedded development.<p>Either way, seems like a fantastic toolkit for working in C!<p>I’m the most excited about the string functions, because idk why but I find myself doing a bunch of string manipulation quite often, and not having to jump out of C or manually implement algos sounds awesome!
It would be nice if functions that take a `const char*` parameter also took a `length` parameter where appropriate.<p>There's a whole lot of `strlen`'ing going on!<p>Cool though
to me, that'd be jart cosmopolitan libc so if I mean to fopen() I can fopen<p><a href="https://justine.lol/cosmopolitan/documentation.html#fopen" rel="nofollow noreferrer">https://justine.lol/cosmopolitan/documentation.html#fopen</a>