guillaume.melquiond at ens-lyon.fr
Sat Sep 16 18:07:27 PDT 2006
Le samedi 16 septembre 2006 à 08:13 -0500, George Corliss a écrit :
> Do you expect undefined situations to be flagged by compilers? If so,
> interval(NaN,NaN) requires a run-time check, and a run-time error message is
> similar to raising an exception or logging. Is it normal practice in
> standard-writing that behavior in "undefined" cases is undefined, but we
> hope that compilers will be as helpful in flagging them as they can
> reasonably be? Where "reasonable" is the choice of the compiler writer?
> Do I understand you correctly?
Yes, you understand me correctly. The "undefined" word has a strange
meaning in the standard: what is undefined is the behavior, not the
conditions in which it occurs. These erroneous conditions are accurately
specified by the standard: there are tens of occurrences of "undefined",
perhaps hundreds. Whenever the word "undefined" is encountered, C++
programmers have to read "Don't even try to do it!". As Steven Clamage
wrote on this list, an undefined behavior can reformat your hard drive.
As for detecting the erroneous conditions at run-time, it depends on the
quality of implementation of the Standard Library. I don't expect them
to be checked by default, as this incurs a performance penalty. Most of
the STLs (all?), however, provide a macro (_GLIBCXX_DEBUG for GCC STL,
_DEBUG for Microsoft STL, _STPL_DEBUG for STLPort, etc) the programmer
can define. With this macro, the program displays an error message and
aborts when it detects erroneous data.
More information about the Std-interval