Earlier quoted context omitted.
> Works nicely on Linux where the syscall interface is explicitly stable, but on many (most?) other platforms this is not the case. There is a footnote on this saying as much: > 3. Where “syscall” means “the lowest level primitive available”. On Linux, it’s always actual syscalls. On Windows, that’s usually NT. On macOS, it’s usually the syscall-wrapper subset of libc because you’re forced to link libc and it’s not q…
What about BSDs?
sp.h: Fixing C by giving it a high quality, ultra portable standard library
21–30 of 222 posts
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#22I agree with most of the criticisms they make. I agree that pointer and length is better than null-terminated strings (although it is difficult in C, and as they mention you will have to use a macro (or some additional functions) to work this in C). Making the C standard library directly against syscalls is also a good idea, although in some cases you might have an implementation that needs to not do this for some re…
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#23Earlier quoted context omitted.
Looks like the default allocator uses mmap(2) for every single allocation , which is horribly inefficient - you map a whole PAGE_SIZE worth of memory for every tiny string. Aside from just wasting memory this will make the TLB very unhappy. It looks like sp_log's string formatting is entirely unbuffered which results in lots of tiny write syscalls.
That seems to be a pretty consistent quality level for the entire library. Look at the implementations in sp_math, yikes.
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#24> Principles > Be extremely portable > sp.h is written in C99, and it compiles against any compiler and libc imaginable. It works on Linux, on Windows, on macOS. It works under a WASM host. It works in the browser. It works with MSVC, and MinGW, it works with or without libc, or with weird ones like Cosmopolitan. It works with the big compilers and it works with TCC. > And, best of all, it does all all of that becaus…
Exactly. This shows that "extremely portable" is actually marketing for "It supports a number of platforms. In my opinion, this number is big".
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#25Yet another slop coded library.
What could possibly go wrong...
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#26Designing software and data structures for performance against unknown use cases on unknown hardware is extremely difficult and the resulting code is much more complicated. Even then, it’s often better to use code written against your actual use case and hardware when performance is that critical.
Things that are off the table might be:
SIMD A highly optimized hash table rewrite Figuring out where inlining or LIKELY causes the compiler to produce better code."
LOL...
Classic vibe coder.
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#27I agree with most of the criticisms they make. I agree that pointer and length is better than null-terminated strings (although it is difficult in C, and as they mention you will have to use a macro (or some additional functions) to work this in C). Making the C standard library directly against syscalls is also a good idea, although in some cases you might have an implementation that needs to not do this for some re…
Null terminated strings have some merits but they should be a completely different data type like in Freebasic.
It seems like one of the worst data structures ever - lookup complexity of a linked list with a expansion complexity of an array list with security problems added as a bonus.
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#28> Every language that depends on third party libraries, like js and python, is getting massively infected with supply chain worms > Only couple of languages not affected are those that don't have a culture of downloading third party code, like C and C++ > Ex js and python developer publishes a 'library' > Library is vibe coded > Published on github amidst GitHub being hit by supply chain attacks, had their source cod…
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#29"Using a language other than C is like using a non-standard feature: it will cause trouble for users. Even if GCC supports the other language, users may find it inconvenient to have to install the compiler for that other language in order to build your program. So please write in C."
The GNU Coding Standard in 1994, http://web.mit.edu/gnu/doc/html/standards_7.html#SEC12
Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library
#30> Principles > Be extremely portable > sp.h is written in C99, and it compiles against any compiler and libc imaginable. It works on Linux, on Windows, on macOS. It works under a WASM host. It works in the browser. It works with MSVC, and MinGW, it works with or without libc, or with weird ones like Cosmopolitan. It works with the big compilers and it works with TCC. > And, best of all, it does all all of that becaus…