errno

Header: <cerrno>

errno is a preprocessor macro used for error indication. It expands to a static(until C++11)thread-local(since C++11) modifiable lvalue of type int.

# Declarations

#define errno /* implementation-defined */

# Example

#include <cerrno>
#include <clocale>
#include <cmath>
#include <cstring>
#include <iostream>
 
int main()
{
    const double not_a_number = std::log(-1.0);
    std::cout << not_a_number << '\n';
 
    if (errno == EDOM)
    {
        std::cout << "log(-1) failed: " << std::strerror(errno) << '\n';
        std::setlocale(LC_MESSAGES, "de_DE.utf8");
        std::cout << "Or, in German, " << std::strerror(errno) << '\n';
    }
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 310C++98it was unclear whether errno is a macroor an identifier with external linkageerrno mustbe a macro

# See also