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
void f1 (const char * str)
errno = 0; // Noncompliant
int i = atoi(str);
if ( 0 != errno ) // Noncompliant
// handle error case???
- MISRA C:2004, 20.5 - The error indicator errno shall not be used.
- MISRA C++:2008, 19-3-1 - The error indicator errno shall not be used.