Draft 2002-02-20

<cerrno>

The <cerrno> header (from the C standard <errno.h> header) declares several macros related to error-handling in the standard library.

EDOM macro

Syntax

int EDOM

Description

Standard library functions that report domain errors set errno to EDOM. A domain error is when the domain of an argument is out of range, such as asking for the square root of a negative number.

The EDOM macro expands to a non-zero integer. The value of EDOM is implementation-defined.

EILSEQ macro

Syntax

int EILSEQ

Description

Standard library functions that report errors in multibyte character sequences set errno to EILSEQ. For example, passing an invalid wide character to the wcrtomb function results in EILSEQ.

The EILSEQ macro expands to a non-zero integer. The value of EILSEQ is implementation-defined.

Note that EILSEQ was omitted from the C++ standard, but because C++ includes the C standard library (Amendment 1), and EILSEQ is part of the C standard, it is also part of the C++ standard.

ERANGE macro

Syntax

int ERANGE

Description

Standard library functions that report range errors set errno to ERANGE. A range error occurs when the result of a function is out of range, such as overflow from the pow function.

The ERANGE macro expands to a non-zero integer. The value of ERANGE is implementation-defined.

errno macro

Syntax

int errno

Description

The errno macro expands into an int lvalue. Standard library functions can store an error code in errno and return an error status to the caller. You can also store a value in errno, such as resetting the error code to zero.

When a program starts, errno is initially zero. No library function resets errno to zero. Any library function might set errno to a non-zero value, even if it is not documented to do so. Therefore, the only time it is safe to check errno is after a library function returns an error status and is documented to set errno in that case.

The C++ standard is not explicit as to whether errno truly is a macro (vs. a variable). The intent of the standard committee is to define errno as a macro, so do not use std::errno, and if your library declares errno as a variable in the std:: namespace, you can define your own macro as follows:

#define errno (::std::errno)