Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      errno

      From cppreference.com
      <cpp‎ |error
       
       
      Diagnostics library
       
      Defined in header<cerrno>
      #define errno /* implementation-defined */

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

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

      The value oferrno is0 at program startup, and although library functions are allowed to write positive integers toerrno whether or not an error occurred, library functions never store0 inerrno.

      [edit]Example

      Run this code
      #include <cerrno>#include <clocale>#include <cmath>#include <cstring>#include <iostream> int main(){constdouble 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';}}

      Possible output:

      nanlog(-1) failed: Numerical argument out of domainOr, in German, Das numerische Argument ist ausserhalb des Definitionsbereiches

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 310C++98it was unclear whethererrno is a macro
      or an identifier with external linkage
      errno must
      be a macro

      [edit]See also

      macros for standard POSIX-compatible error conditions
      (macro constant)[edit]
      displays a character string corresponding of the current error tostderr
      (function)[edit]
      returns a text version of a given error code
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/error/errno&oldid=173436"

      [8]ページ先頭

      ©2009-2025 Movatter.jp