3 ms·
> For instance, if you write f(g(), h()), C doesn't define whether g or h gets called first. That's unSPECIFIED behavior, not unDEFINED behavior. There's a bi
by GFK_of_xmaspast 11y ago
> For instance, if you write f(g(), h()), C doesn't define whether g or h gets called first.
That's unSPECIFIED behavior, not unDEFINED behavior. There's a big difference.
- JoshTriplett 11y agoYou're right, sorry. I should have looked up that specific example before using it, and used an example that fell under "undefined" behavior. My point, though, was that the compiler doesn't have to explicitly notice the program using undefined behavior and choose a behavior. Rather, the compiler may simply not consider undefined behavior at all, act as though only defined behaviors can occur, and have undefined behavior be whatever happens due to the lack of explicit handling. The compiler can emit code that handles the defined behavior, and whatever that code happens to do in other cases will be the compiler's "handling" of undefined behavior. Thus, making the compiler explicitly flag undefined behavior isn't just a matter of finding all the places where the compiler explicitly handles undefined behavior and emitting a warning there. It would require noticing everywhere the compiler simply doesn't consider cases the spec doesn't require it to consider.