TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

An usable and maximally efficient C standard library

48 pointsby ssklashover 1 year ago

15 comments

asveikauover 1 year ago
There are red flags in some of the function signatures that the author doesn&#x27;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 &quot;c standard library&quot; 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&#x27;t pass a &quot;production quality c code&quot; at-a-distance sniff test.
评论 #38524663 未加载
评论 #38524548 未加载
评论 #38524432 未加载
评论 #38524923 未加载
评论 #38525432 未加载
评论 #38525172 未加载
acuozzoover 1 year ago
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&#x27;t using aligned_alloc in at least some places nowadays?<p>Having to do the following song &amp; dance sucks.<p><pre><code> #define malloc xmalloc #include &lt;yourthing.h&gt; #undef malloc </code></pre> [1] <i>I&#x27;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&#x27;m aware that its abstract model of computation and semantic complexity make it anything but &quot;low-level&quot;, but C can get rather close on some architectures with some compilers.</i>
allanrboover 1 year ago
Fine looking general helper functions, but I find it a bit confusing to call this a &quot;standard library&quot;. That has a particular meaning in C&#x2F;C++ already.
评论 #38524163 未加载
linkddover 1 year ago
It&#x27;s not a &quot;standard&quot; library though...<p>It&#x27;s a nice &quot;toolbox&quot;, but definitely not &quot;standard&quot; (word which has a very specific definition).
saagarjhaover 1 year ago
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 &quot;maximally&quot; 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> &#x2F;* Function to concatenate multiple strings into a new string *&#x2F; 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>
krackersover 1 year ago
If you want a sledgehammer, CoreFoundation is open sourced and works on Linux.
评论 #38524820 未加载
samsquireover 1 year ago
Thank you for this.<p>I really enjoy C (I&#x27;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&#x27;t yet wrestled with much yet.
RcouF1uZ4gsCover 1 year ago
Some observations:<p>1. Who owns the memory? How is the memory freed?<p>2. C doesn&#x27;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)
_benjover 1 year ago
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!
评论 #38528978 未加载
secondcomingover 1 year ago
It would be nice if functions that take a `const char*` parameter also took a `length` parameter where appropriate.<p>There&#x27;s a whole lot of `strlen`&#x27;ing going on!<p>Cool though
typonover 1 year ago
Any maximally efficient C library should ideally do zero allocations and if it needs to, ask the user how they manage their memory.
csdvrxover 1 year ago
to me, that&#x27;d be jart cosmopolitan libc so if I mean to fopen() I can fopen<p><a href="https:&#x2F;&#x2F;justine.lol&#x2F;cosmopolitan&#x2F;documentation.html#fopen" rel="nofollow noreferrer">https:&#x2F;&#x2F;justine.lol&#x2F;cosmopolitan&#x2F;documentation.html#fopen</a>
gren236over 1 year ago
That&#x27;s the most &quot;C&quot; readme that I&#x27;ve seen. Looks really interesting though.
tedunangstover 1 year ago
sorted_ulong_long_ptrs, where have you been all my life?
dhooperover 1 year ago
“Maximally efficient”…uses zero terminated strings. Facepalm