errno
is a facility of C++ which should in theory be useful, but which in practice is poorly defined by ISO/IEC 14882:2003. A non-zero
value may or may not indicate that a problem has occurred; therefore errno
shall not be used.
Even for those functions for which the behaviour of errno
is well defined, it is preferable to check the values of inputs before
calling the function rather than relying on using errno
to trap errors.
Noncompliant code example
#include <cstdlib>
#include <cerrno>
void f1 (const char * str)
{
errno = 0; // Noncompliant
int i = atoi(str);
if ( 0 != errno ) // Noncompliant
{
// handle error case???
}
}