Live data from Hacker News

sp.h: Fixing C by giving it a high quality, ultra portable standard library

spader.zone

21–30 of 222 posts

Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library

#21

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?

syscalls

Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library

#22

I 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.

Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library

#23
post #7

Earlier 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.

Oh man. Oof. I'm sure there must be some repository out there that has an AGENTS.md but isn't pure slopcode, but I haven't seen it yet. The number of people who can be trusted to vibe code "responsibly" is probably about the same as the number of people who can be trusted to write memory safe C.

Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library

#24
post #11

> 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".

We support extreme portability for sufficiently large values of two.

Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library

#26
"The library’s stance, to put it simply, that the juice ain’t worth the squeeze when it comes to low level, compute-bound performance.

Designing 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

#27

I 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.

Are there other merits than availability of literals in C?

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
post #2

> 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…

Thanks for this comment, I was about to bookmark the repo for later you saved me the time.

Re: sp.h: Fixing C by giving it a high quality, ultra portable standard library

#29
We should have left C in the 90's already, but then FOSS happened,

"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…

I could not even find a mention what platform it supports. There is a Linux example on the bottom. Have never seem a libc implementation that does not even mention for which platforms it is meant.
Post reply on HN