Re: Some errors in MIT's intro C++ course
On Sep 17, 1:27 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
In comp.lang.c++ James Kanze <james.ka...@gmail.com> wrote:
The "undefined behavior" should be a program crash on any
good implementation (at least one used by beginners). It is
with VC++ and with g++ (at least when invoked correctly).
No. It is in VC++ when compiling in debug mode, and in g++
only if you define an obscure preprocessor macro (namely
_GLIBCXX_DEBUG).
In other words, it is the behavior when the compiler is invoked
correctly. Exactly what I said. (I'm not sure what you mean by
"debug" mode with VC++. VC++ doesn't have a "debug" mode, and I
don't know what VC++ does by default. The IDE does have a debug
mode, which is what it defaults to.)
When compiling normally with optimizations, you most probably
won't get a crash, but erratic behavior.
You choose the options you compile with. If the profiler says
you can't afford bounds checking, then you turn it off. But if
you can't afford bounds checking, then you can't use at().
(And even if you *are* compiling in debug mode, you are still
not *guaranteed* to get a crash because the standard says so.
Unless Microsoft and the gcc team have *promised* that it will
crash now and in the future for eternity, you have no
guarantee.)
You are compiling with a specific compiler. Always. Both
Microsoft and g++ have documented the meaning of the various
command line options. You're using a documented feature.
Beyond that, it's a question of QoI, and how much the vendor
cares about his customers. But that's always the case. (You
can imagine the opposite as well. You have a time critical
application which requires bounds checking to be turned off in
order to run in an acceptable time. What guarantees you that
the next release will have the option of turning it off?)
--
James Kanze