Live data from Hacker News

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

spader.zone

191–200 of 222 posts

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

#191

https://spader.zone/sp/#null-terminated-strings-are-the-devi... Pointer/length is not just for strings - but for all arrays. See my proposal: https://www.digitalmars.com/articles/C-biggest-mistake.html

I use a C dialect with (ptr,ptr) slices and (ptr,ptr,ptr,ptr) buffers. Effectively a different programming language, still uses standard C compiler.

https://github.com/gritzko/libabc

In this day and age, the top problem is Claude bringing lots and lots of bad C into the code base. Takes a weekend to clear the week's mess.

https://github.com/gritzko/beagle

In a cleared codebase though all the usual C memory bugs are virtually non-existant. When did I see core dump last time? I do not remember. Thus feel no urge to use Zig or Rust.

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

#192
post #72

Just taking a quick look at the atomics section: First, (on unix) it's wrapping pthread mutex. That's part of libc! (Technically it might not be libc.so, but it's still the standard library.) Also, none of the atomics talk about the memory model. You don't _have_ to use the C11 memory model (Linux, for example, doesn't). But if you're not using the C11 memory model and letting the compiler insert fences for you, you…

Yes, unfortunately the threading primitives require libc. Ditto subprocesses. It's on my list. But regarding: "Oops... apparently this is vibecoded. Welp, I just wasted ten minutes of my life reviewing slop that I'm not going to get back." Do not talk to people like this. I don't care if you don't like the library, or if you found a flaw in it. I am a regular person who wrote this code for no other reason than I thou…

Many of us are forced to spend time reviewing automatically generated code for work, so there is an understandable reluctance to be asked to do the same here as well.

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

#193

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

Portability across compilers is orthogonal to portability across target architectures.

This is true, but it would probably be good to be specific what is meant by "portable". There is also the dimension of operating system.

It sounds like it has a goal of being "extremely portable" across compilers, (although I'm curious how many compulers it is actually tested against) but only somewhat portable across architectures and operatings systems, just hitting the most popular ones.

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

#194

I spent a bit of time implementing parts of a C runtime for the brief tenure I had maintaining LLVM's libc. I quickly came the realization that a lot of the interfaces that made it all the way to standardization were trash. How the language is standardized is still comical to me. I agree with TFA that C style strings are trash.

In this day and age, the value of C standard library is approaching zero. Is is basically an unfirm looping trajectory of CS thought left over 50 years. That amount of code can be recreated pretty quick today. So why bother. Unless it is a syscall or somehow specially treated by the compiler (memcpy etc), there is no special value in it.

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

#195

Just taking a quick look at the atomics section: First, (on unix) it's wrapping pthread mutex. That's part of libc! (Technically it might not be libc.so, but it's still the standard library.) Also, none of the atomics talk about the memory model. You don't _have_ to use the C11 memory model (Linux, for example, doesn't). But if you're not using the C11 memory model and letting the compiler insert fences for you, you…

> Oops... apparently this is vibecoded. Welp, I just wasted ten minutes of my life reviewing slop that I'm not going to get back. you interested in project and spent some time researching it, but stop when understand that it is vibe-coded (be it or not)? Why care if it is interesting to you?

"but stop when understand"

English language as she is spoke

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

#196
post #137

Earlier quoted context omitted.

It's an odd stance for a C library. In my experience, odd platforms are the main place that C is used in 2026. If you're writing a new Windows or Linux or MacOS or WASM program, it's not likely to be in C. But lots of new microcontroller software is still being written in C. And he's already hit the hard targets. Many obscure OS's are generally UNIX like and should be easy ports. Many obscure arch's usually are runni…

Aren't these MCUs predominantly ARM-based, with some RISC-V thrown in? I see no contradiction in the desire to support x64 (because it would be ridiculous not to), ARM, and likely RISC-V, but not the venerable but now-fringe architectures like MIPS or Sparc or 68040 or even x86.

AfAIK lots of 8051-based microcontrollers that are quite modern, such as Silicon Labs EFM8 line[1] or STC which in addition to 8-bit 8051's also has 32-bit 8051 variants[2].

[1]: https://www.silabs.com/mcu/8-bit-microcontrollers

[2]: https://www.stcmicro.com/stc/stc32g.html

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

#197
post #70
post #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/sta…

For reference, Dialup Internet (E.G. ~2-3KByte/sec transfer) was NOT uncommon even into the early 2000s. In 1994 even dialup internet connections were rare and most software distribution occurred by floppy disk (encased in hardshell plastic). _storage_ space was also at a major premium with internal hard disk size indexed in CHS rather than LBA and new (rarely seen by most end consumers) models barely passing 1GB in…

It's been interesting seeing the retrospective flattening of computer history. I suppose it's inevitable over time. I wonder how bad it will get.

"In the 1990s, 'hackers' would 'dial up' their flip phones to local BBSes (called 'phreaking'), where they played and exchanged small Flash games (the 'demo scene')." /s

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

#198

https://spader.zone/sp/#null-terminated-strings-are-the-devi... Pointer/length is not just for strings - but for all arrays. See my proposal: https://www.digitalmars.com/articles/C-biggest-mistake.html

I use a C dialect with (ptr,ptr) slices and (ptr,ptr,ptr,ptr) buffers. Effectively a different programming language, still uses standard C compiler. https://github.com/gritzko/libabc In this day and age, the top problem is Claude bringing lots and lots of bad C into the code base. Takes a weekend to clear the week's mess. https://github.com/gritzko/beagle In a cleared codebase though all the usual C memory bugs are v…

Congrats! I had many years of chasing memory bugs. It certainly influenced the design of D a lot.

Interestingly, I rarely make a memory bug these days. Too much experience, I've just learned not to make them.

But I still prefer to use language features that make it easier to not make such errors.

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

#199
post #60

This doesn't look good: c8 buf [SP_PATH_MAX] = sp_zero; sp_cstr_copy_to_n(path, len, buf, SP_PATH_MAX); since #define SP_PATH_MAX 4096 There should be a fallback for very long paths.

Can you show me a realistic case with a longer path?

I guess the c8 means you don't plan on supporting Unicode on Windows? If you do, there's the 32768 "character" max path which since Win10 is opt-in without jumping through hoops.

https://learn.microsoft.com/en-us/windows/win32/fileio/maxim...

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

#200
post #80

First, thanks for sharing this link, it was an interesting read! A few remarks below. I had a hard time reading the wc code in the article. First I had to go to the GitHub to understand that "da" stands for dynamic array, and then understand that what the author calls wc is not at all the wc linux commands, which by default gives you the number of lines, words, and characters in a file, not the count of occurrences o…

To be portable it's probably best to use the pthreads API for everything, make no additional assumptions, and rely on the user to provide the implementation. Consider what happens when someone is working with OpenMP, CUDA, or similar and attempts to make use of a dependency that in turn makes use of your library. The easier it is to understand the assumptions made by your library the better.

I agree with that. I'm just stating that it's contradictory with the project's own principles.

> Program directly against syscalls

It's the very first one of the listed principles. In the paragraph after this title it even says it "must" be the case in italic to insist on it, and there's a footnote to define what they mean, which is very clear in that pthreads should be out according to this principle.

Post reply on HN