##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# errno

From cppreference.com
< cpp‎ | error

Defined in header `<cerrno>` |  |
#define errno /*implementation-defined*/ |  |

`errno` is a preprocessor macro used for error indication.

It expands to a static modifiable lvalue of type int. | (until C++11)
It expands to a thread-local modifiable lvalue of type int. | (since C++11)

Several standard library functions indicate errors by writing positive integers to `errno`. Typically, the value of `errno` is set to one of the error codes, listed in `<cerrno>` as macro constants that begin with the letter `E`, followed by uppercase letters or digits.

The value of `errno` is ​0​ at program startup, and although library functions are allowed to write positive integers to `errno` whether or not an error occurred, library functions never store ​0​ in `errno`.

### [edit] Example

Run this code

    #include <iostream>
    #include <cmath>
    #include <cerrno>
    #include <cstring>

    int main()
    {
        double not_a_number = std::log(-1.0);
        if (errno == EDOM) {
            std::cout << "log(-1) failed: " << std::strerror(errno) << '\n';
        }
    }

Output:

    log(-1) failed: Numerical argument out of domain

### [edit] See also

E2BIG, EACCES, ..., EXDEV | macros for standard POSIX-compatible error conditions (macro constant) [edit]
perror | displays a character string corresponding of the current error to stderr (function) [edit]
strerror | returns a text version of a given error code (function) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/error/errno&oldid=69291"