News for hackers. Stuff that matters.
Re:The C3 Programming Language by Windeycastle on Saturday January 03, 2026 @02:13PM (#46480364)
The way I reason about it is that the contracts are more soft conditions that you expect to not really reach. If something always has to be true, even on not-safe mode, you use "actual" code inside the function/macro to check that condition and fail in the desired way.
Re:The C3 Programming Language by coldtea on Saturday January 03, 2026 @03:16PM (#46481067)
>The way I reason about it is that the contracts are more soft conditions that you expect to not really reach

What's the difference from an assert then?

Re:The C3 Programming Language by lerno on Saturday January 03, 2026 @04:11PM (#46481613)
The difference from an assert is that for "require" they are compiled into the caller frame, so things like stack traces (which is available in safe mode) will point exactly to where the violation happened.

Because of inlining them at the call site happens, static analysis will already pick up some obvious violations.

Finally, these contracts may be used to compile time check otherwise untyped arguments to macros.

Re:The C3 Programming Language by cwillu on Saturday January 03, 2026 @02:21PM (#46480444)
“However, violating either pre- or post-conditions is unspecified behaviour, and a compiler may optimize code as if they are always true – even if a potential bug may cause them to be violated”

This implies that a compiler would be permitted to remove precisely that actual code that checks the condition in non-safe mode.

Seems like a deliberately introduced footgun.

Re:The C3 Programming Language by cloud-oak on Saturday January 03, 2026 @02:30PM (#46480557)
My understanding of this was that the UB starts only after the value is passed/returned. So if foo() has a contract to only return positive integers, the code within foo can check and ensure this, but if the calling code does it, the compiler might optimize it away.
Re:The C3 Programming Language by gku on Saturday January 03, 2026 @02:42PM (#46480713)
Re:The C3 Programming Language by cwillu on Sunday January 04, 2026 @05:27AM (#46486673)
Assuming that is correct, it's still exactly the same footgun. Checks like that are introduced to guard against bugs: you are strictly safer to not declare such a constraint.