3 ms·
> Which are...? I guess they're different for different interviewers. The one I would use is something about undefined behavior. I mean, the fact that it exis
by yeputons 3y ago
> Which are...?
I guess they're different for different interviewers.
The one I would use is something about undefined behavior. I mean, the fact that it exists and consequences. For example: "this program works, but if I add this line of code at the very end, the program crashes. Can be I sure that it crashed because of that line or some incorrect inputs to that line?"
In (almost) all other languages the answer is "Yes". Not in C++ or C. You may have a faulty program in the first place that just happen to not crash.
All other quirks and syntax can be picked up when needed. You can play around and investigate. But undefined behavior requires one to think and debug in a very different mindset. One cannot assume that a program that does not crash and gives a correct answer will do that if extended.
- krona 3y agoOr, compile with -fsanitize=undefined...
- compiler-guy 3y agoubsan is awesome, but it's not too hard to construct programs that contain undefined behavior that -fsanitize=undefined won't catch.
- yeputons 3y agoIt only helps so much. I've taught to freshmen students who have personally encountered dozens of different false positives and false negatives not only with sanitizers, but with compiler warnings as well. Nothing extraordinary, just `-Wall -Wextra -Werror` with the latest available GCC/Clang on the latest available Ubuntu LTS. Some examples (some library bugs are also included): https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98677 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98677 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105729 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105729 https://github.com/llvm/llvm-project/issues/59432 https://github.com/llvm/llvm-project/issues/59432 https://github.com/boostorg/dll/issues/30 https://github.com/boostorg/dll/issues/30 https://github.com/boostorg/asio/commit/71964b22c7fade69cc4caa1c869a868e3a32cc97 https://github.com/boostorg/asio/commit/71964b22c7fade69cc4c... https://github.com/chriskohlhoff/asio/issues/997 https://github.com/chriskohlhoff/asio/issues/997 I've also seen fun examples of a program working with all sanitizers in 14 modes across 3 OSes (GCC and Clang on Ubuntu, Apple Clang on macOS, Visual Studio on Windows), and _only_ failing with Visual Studio Release mode. It was an array overflow. Just was not caught by sanitizers. Mind you: no weird C++ magic, just standard coding exercises.