7 comments

  • EPWN3D16 minutes ago
    Author here, I posted this in Show HN but someone clearly beat me to it. So I&#x27;ll repost my blurb from there.<p>Various patterns for safer C programming have been cargo-culting around the industry for decades. Because the language evolves intentionally slowly, these patterns rarely get folded into the language as first-class constructs and are passed down through the generations in a sort of oral tradition of programming.<p>lib0xc leverages GNUC extensions and C11 features to codify safer C practices and patterns into real APIs with real documentation and real testing. Reduce your casts to and from `void *` with the `context_t` tagged pointer type. Enable type-checked, deferred function invocation with `call_t`. Interrogate structure descriptors with `struct_field_t`. Stop ignoring `-Wint-conversion` and praying you won&#x27;t regret it when you assign a signed integer to an unsigned integer and use `__cast_signed_unsigned`. These are just a few of lib0xc&#x27;s standard-library-adjacent offerings.<p>lib0xc also provides a basic systems programming toolkit that includes logging, unit tests, a buffer object designed to deal with types, a unified Mach-O and ELF linker set, and more.<p>Everything in lib0xc works with clang&#x27;s bounds-safety extensions if they are enabled. Both gcc and clang are supported. Porting to another environment is a relatively trivial effort.<p>It&#x27;s not Rust, and it&#x27;s not type safety, but it&#x27;s not supposed to be. It&#x27;s supposed to help you make your existing C codebase significantly safer than it was yesterday.<p>My employer holds the copyright and has permitted its release under the MIT license.
  • jabl13 minutes ago
    Unfortunate naming. I thought this was about <a href="https:&#x2F;&#x2F;libxc.gitlab.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;libxc.gitlab.io&#x2F;</a> but there&#x27;s an extra &#x27;0&#x27; in the name here.
  • raggi57 minutes ago
    there are no good reasons we don&#x27;t do this in the standards themselves, C, C++, and POSIX should all be working on editions that add safer APIs and mark unsafe APIs as deprecated, to start a long term migration. we know how to do this, we&#x27;ve had a lot of success with this. there are real engineering concerns, sure, but they&#x27;re not reasons to not do it. compilers and library chains can retain support for less safe variants for plenty of time.
    • AlotOfReading30 minutes ago
      The reason this wasn&#x27;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&#x27;t enough, well it was certainly too expensive to provide as a debug option. And if it wasn&#x27;t too expensive to provide as a debug option, the implementors should really lead the way first. And on and on.<p>The C committee at least seems to get it now. The C++ committee still doesn&#x27;t, led in large part by Bjarne.
    • zbentley31 minutes ago
      There are only two kinds of standards: ones that prioritize stability and backwards compatibility over usefulness and security, and ones nobody uses.
  • nxobject37 minutes ago
    I&#x27;m curious – is MSFT using this in production, or is this a &quot;20% time&quot; project? I&#x27;m not sure MSVC could compile the GNU extensions used.
    • EPWN3D20 minutes ago
      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&#x27;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.
  • atilimcetin58 minutes ago
    The title looks very promising. I’ve added this library to my to-do list to take a deeper look at it. Using this standart library within restricted safe subset of C++ can be a strong opponent for Zig (at least for myself).
    • EPWN3D18 minutes ago
      Haven&#x27;t really verified that it works with C++, but I tried my best to guard the stuff I knew would be problematic with #if __cplusplus. Happy to have a PR that makes C++ happier with it.
  • matheusmoreira1 hour ago
    Interesting. I&#x27;ll be studying this later tonight so I can apply it to my C projects. Especially clang&#x27;s -fbounds-safety.
  • platinumrad3 hours ago
    I truly hope something like this catches on. There is so much low hanging fruit in both the C and C++ standard libraries. Spatial memory could be 90% solved in both languages by mandating the use of safe interfaces.