Live data from Hacker News

Lib0xc: A set of C standard library-adjacent APIs for safer systems programming

github.com

61–70 of 103 posts

Re: Lib0xc: A set of C standard library-adjacent APIs for safer systems programming

#61
post #6

I'm curious – is MSFT using this in production, or is this a "20% time" project? I'm not sure MSVC could compile the GNU extensions used.

> I'm not sure MSVC could compile the GNU extensions used.

The supported platforms only list Linux and Mac. Notably missing from that list is any of the BSDs (not counting what may or may not remain of BSD under the Mac hood).

Re: Lib0xc: A set of C standard library-adjacent APIs for safer systems programming

#62

Earlier quoted context omitted.

I suspect in 20 years Windows will be a Linux distribution with a compatibility layer.

People say that kind of thing on HN every now and then. I have no idea why this idea is around, it's a complete fantasy in my opinion. I say this as someone who mostly uses Linux.

> I have no idea why this idea is around,

To the best of my fallible knowledge, the notion was first popularized via http://esr.ibiblio.org/?p=8764>.

Re: Lib0xc: A set of C standard library-adjacent APIs for safer systems programming

#63

Earlier quoted context omitted.

If someone needs more than C provides, why on earth would they choose C++? No rational person is going to want to have to deal with 10x the number of foot guns. Literally anything when moving from C is better than C++.

Switching to C++ is relatively easy in an existing codebase. It's in many cases as simple as renaming a file from .c to .cpp. But for writing something from scratch it's better to use Rust.

> It's in many cases as simple as renaming a file from .c to .cpp.

That is rather optimistic, but, for example, scpptool has a feature [1] that auto-converts from C to a subset of C that can (hopefully) be compiled with clang++. If the original C source uses C11 extensions, clang++ seems to generally produce warnings rather than compile errors.

> But for writing something from scratch it's better to use Rust.

scpptool attempts to make C++ a more viable option by enforcing a memory and data race safe subset using a similar safety strategy.

[1] https://github.com/duneroadrunner/SaferCPlusPlus-AutoTransla...

Re: Lib0xc: A set of C standard library-adjacent APIs for safer systems programming

#64
post #17

Earlier quoted context omitted.

> This might be a dumb question, but using this + clang bounds-safety, whats the difference between this and something like Zig or Odin. I really need to learn more about Zig, but from what I know, there are still worlds of possibilities that a modern, well-designed language offers over something like lib0xc. Zig's ability to evaluate any expression at compile-time is one such example. But generally, lib0xc gives you…

Why not pick a different language if you want different features? Why does C specifically need to change, if there are already Zig, Rust etc.? Why Must C be safe, rather than people writing safer code in it or transfering to other languages if they cannot be bothered?

[flagged]

Re: Lib0xc: A set of C standard library-adjacent APIs for safer systems programming

#65
post #46
post #25

Earlier quoted context omitted.

That produces a bit of a chicken and egg probablem for a stdlib overhaul. Compilers and libc implementations don't have a strong reason to implement safer APIs, because if it is non-standard then projects that want to be portable won't use it , but it won't get standardized unless they do add safer APIs. So the best hope is probably for a third party library that has safet APIs to get popular enough that it becomes a…

I think the real failing is that new language features then must be prototyped by people who have a background in compilers . That's a very small subset of the overall C community. I don't have any clue how to patch clang's front end. I'm not a language or compiler person. I just want to make stuff better. There needs to be a playground for people like me, and hopefully lib0xc can be that playground.

By adding to the language itself, you mostly make stuff worse. The major reason why C is useful is its quite stable syntax and semantics. Language is typically not the area where you want to add code. It's much better (and much easier) to invent function APIs. See how they shake out, if they're good you might get some adoption.

Re: Lib0xc: A set of C standard library-adjacent APIs for safer systems programming

#66
post #26

Is there anything in here for something like a "slice" or dynamically sized array that carries its length along with it?

Just use compiler option -std=c++20 and use std::span. Don't try reinventing it in C.

std span is not bounds checked.

Re: Lib0xc: A set of C standard library-adjacent APIs for safer systems programming

#67
post #9
post #6

I'm curious – is MSFT using this in production, or is this a "20% time" project? I'm not sure MSVC could compile the GNU extensions used.

Author here. It is not currently in production, but it is part of a project in Azure which will go to production at some point. I'm actually leaving Microsoft next week and fully intend to keep working on it if I can reach an agreement to do so with my new employer.

If an agreement can't be reached with your new employer are you certain that folks at Microsoft will continue maintaining this library? I'd like to experiment with it but have trepidation regarding future development.

Re: Lib0xc: A set of C standard library-adjacent APIs for safer systems programming

#68
post #45
post #38

This is great. Other things needed for a great C development environment are a standardized build process plus build tools and a standardized packaging system.

Thanks! I agree, a better build story for C projects is desperately needed.

What most people forget is that software is meant to be used as part of the system. The rush to adopt packaging tools like npm and cargo prevent standardization of system tools. On debian, installing tools should be as simple as ‘apt install’, but now you have to check what toolchain version you install then download GB of stuff from the internet. And that for each software. Easy deps donwload for devs means maintenance nightmare for admins and users.

Re: Lib0xc: A set of C standard library-adjacent APIs for safer systems programming

#69
post #54

Earlier quoted context omitted.

The reason this wasn't done by the standards committees is that they spent decades refusing to admit there was even a problem they could help fix. And if there was a problem, it was easily avoided by just writing better code. And if writing better code wasn't enough, well it was certainly too expensive to provide as a debug option. And if it wasn't too expensive to provide as a debug option, the implementors should r…

This is a misrepresentation based on a misunderstanding on how standardization works. The C standard committee has long recognized the need for better safety and carefully made it possible so that C could be implemented safely. But the process is that vendors implement something and then come together during standardization so that it is compatible, not that the standardization is the government that prescribes top-d…

Stop mixing C and C++, tons of people on Unix still hate C++ (Motif a bit less) for being un-Unixy and megacomplex, even more today. Die had Unix and C people created Plan9 and now Go, which is maybe the other succesor to C before Inferno and Limbo, where programming it's more simpler than the whole C and POSIX clusterfux (even Plan9 and 9front itself can be called a "Unix 2.0").

C++ is something else. Heck, it's often far more bound to a Windows domain (and for a while Be/Haiku) than Unix itself by a huge stretch.

Re: Lib0xc: A set of C standard library-adjacent APIs for safer systems programming

#70
post #43

Earlier quoted context omitted.

I think most people who are into c that I’ve met quite like header only libraries. Copy paste as a package manager does have its benefits.

I mostly just install a -dev package on Linux and I am done.

Not even that; OpenBSD and Hyperbola GNU don't split packages between headers and binaries. Install a package, you get both.
Post reply on HN