r/C_Programming • u/8d8n4mbo28026ulk • Aug 26 '26
Reliability Lessons From SQLite - Richard Hipp | SSW 2026
https://www.youtube.com/watch?v=V_qzqY1bb7I
39
Upvotes
r/C_Programming • u/8d8n4mbo28026ulk • Aug 26 '26
View all comments
Show parent comment
3
u/8d8n4mbo28026ulk Aug 26 '26 edited Aug 27 '26
Ah, I think you've misunderstood me. If something indicates a bug in your program (or an interface contract violation), it should always* be an assertion, never an error! When I say keep the assertion in release builds, I mean it just to guide the compiler, nothing more.
Suppose you want to iterate an non-empty linked list:
In a release build, that
assert()becomes__builtin_assume(node != NULL). The compiler can then turn thatwhile-loop into ado-while-loop and eliminate a branch. This example was with a nullability check, but many things can be helpful to the compiler, as I said. Range checks, wrap-around checks, known-bits, pointer alignment... I often do assertions on those and obviously they can be very useful for optimisation purposes.*Having rewatched the
NEVER()bit of the talk, I believe they're using these macros mainly to shield against platform shenanigans. That's perhaps a good example of turning an assertion into an error-check, even though the former fits the purpose better.