Live data from Hacker News

Contracts for C

gustedt.wordpress.com

111–114 of 114 posts

Re: Contracts for C

#111

Earlier quoted context omitted.

Safer in what sense? We have no idea whether this hypothetical code is in a userspace application that can exit safely at any time or a hard real time system where panicking could destroy hardware. A lot of important programs (like the Linux kernel) don't operate strictly on the exact letter of the standard's UB semantics. They do things like add compiler flags to specify certain behaviors, or assume implementation d…

I will never understand how C developers can catastrophize over Rust panics, a language that has a panicless "_try" version of every panic causing function that returns a Result instead, while simultaneously accepting the infinite growth of ever harder to avoid UB in C/C++ and telling people to never have undefined behavior in their code. If you think dealing with undefined behavior is easy and you assume that people…

We removed 30% of UB in the core language already for C2y and are in progress of removing more, so there is no "infinite growth of ever hard to avoid UB". For many UB the right way is indeed to panic and in C you can often achieve this with the UB sanitizer (but not for all).

Re: Contracts for C

#112

Contracts getting proposed but still no slice/span type or even standardization of that new clang feature that makes f(int n, int a[n]) Actually do what it looks like it does. Sigh

You can just define a span type yourself: https://uecker.codeberg.page/2025-07-02.html

What new clang feature are you talking about?

Re: Contracts for C

#113
post #112

Contracts getting proposed but still no slice/span type or even standardization of that new clang feature that makes f(int n, int a[n]) Actually do what it looks like it does. Sigh

You can just define a span type yourself: https://uecker.codeberg.page/2025-07-02.html What new clang feature are you talking about?

-fbounds-safety
Post reply on HN