Repository navigation
Clarification about the usage of Undefined Behavior in C3 #3642
Replies: 4 comments 12 replies
|
C3 fixes C's problems, including default initialization, without denying the optimizer the benefits of undefined behavior. It's a very different look at the same problem space without opting to sidestep it entirely. |
Undefined behavior (UB) just means that the compiler cannot guarantee that your program will run as expected if any of C3's listed UB occurs. It is possible to avoid a lot of UB by doing things like zeroing variables and allocated memory, but these fixes come with an intrinsic cost. C3 has a lot of safe behavior by default, but it also gives the user the freedom to bypass this safety when necessary. This freedom comes with the inherent risk of UB, and so C3 has to allow it and be clear that it exists. Languages with no / very little UB exist, but they come with the cost of either being slow to run (interpreted languages), or limit the possibility space that programmers can explore greatly (Rust and other safe languages). C3 does the best it can by making undefined behavior abort in debug builds whenever possible, which in my experience is really all you need. As for inheriting UB from C, UB is really more of a fact of computers rather than C specifically. Without seriously limiting what you can do on a computer, there is always a possibility that a program will do something incorrect and cause UB. |
|
If you compile with --safe=yes you retain the checks in the final executable, even at higher optimization levels. It is up to you whether the compiler should insert safety checks or assume that the program does not have these bugs. It is a trade-off between performance and safety. So it is up to you as the user to decide if runtime checks should be there or not. |
|
It would be nice if we had something like Go's |
Uh oh!
There was an error while loading. Please reload this page.
Currently reading https://c3-lang.org/language-rules/undefined-behaviour/ and what caught my attention is this paragraph:
The emphasized line by me is what baffled me.
Isn't delivering a secured release version of my application, the whole point?
Why do we even allow Undefined Behavior in C3?
C29 (a.k.a. C2y) attempts to limit the Undefined Behavior by fixing lots of things; an example would be by default initializing variables, thus helping the user by accidentally reading uninitialized variable(s).
Isn't C3 supposedly the attempt to fix C's problems?
Why retaining, let alone inheriting this problematic behavior from C?
...and please don't tell me it's "because of C ABI compatibility"!
All reactions