{"id":284324,"date":"2017-04-03T07:00:02","date_gmt":"2017-04-03T03:00:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284324"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284324","title":{"rendered":"\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 C"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/9f0\/658\/511\/9f0658511b7b48f7b67b68f6174c12f2.jpg\"\/><\/p>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0438, \u0443\u0432\u044b, \u043d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438. \u0418 \u0435\u0441\u043b\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0442\u043e \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 (<a href=\"https:\/\/en.wikipedia.org\/wiki\/C_standard_library\">C Standard Library<\/a>) \u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/POSIX\">POSIX<\/a>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043e\u0448\u0438\u0431\u043e\u043a. <br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f errno \u0438 \u043a\u043e\u0434\u044b \u043e\u0448\u0438\u0431\u043e\u043a<\/h3>\n<p>  <\/p>\n<h4><a href=\"https:\/\/en.wikipedia.org\/wiki\/Errno.h\">&lt;errno.h&gt;<\/a><\/h4>\n<p>  <b>errno<\/b> \u2013 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0445\u0440\u0430\u043d\u044f\u0449\u0430\u044f \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u043e\u0448\u0438\u0431\u043a\u0438. \u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u0432\u043e\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f <b>errno<\/b>, \u0447\u0435\u043c \u0438 \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0435\u0451 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0432 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435. \u041e\u0431\u044b\u0447\u043d\u043e <b>errno<\/b> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u043a\u0440\u043e\u0441\u0430, \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u0432 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0435\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0431\u0443\u0444\u0435\u0440. \u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <b>errno<\/b> \u0440\u0430\u0432\u043d\u043e \u043d\u0443\u043b\u044e. <\/p>\n<p>  \u0412\u0441\u0435 \u043a\u043e\u0434\u044b \u043e\u0448\u0438\u0431\u043e\u043a \u0438\u043c\u0435\u044e\u0442 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0438 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0430\u0445 \u043f\u0440\u0435\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 <b>#if<\/b>. \u0412 \u0446\u0435\u043b\u044f\u0445 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b <code>&lt;errno.h&gt;<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u0430\u043a\u0440\u043e\u0441\u044b, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u0434\u0430\u043c \u043e\u0448\u0438\u0431\u043e\u043a. <\/p>\n<p>  \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442 ISO C \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u0434\u044b: <\/p>\n<ul>\n<li><b>EDOM<\/b> \u2013 (<b>E<\/b>rror <b>dom<\/b>ain) \u043e\u0448\u0438\u0431\u043a\u0430 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f.<\/li>\n<li><b>EILSEQ<\/b> \u2013 (<b>E<\/b>rror <b>i<\/b>nva<b>l<\/b>id <b>seq<\/b>uence) \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u0430\u0439\u0442\u043e\u0432.<\/li>\n<li><b>ERANGE<\/b> \u2013 (<b>E<\/b>rror <b>range<\/b>) \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0432\u0435\u043b\u0438\u043a.<\/li>\n<\/ul>\n<p>  \u041f\u0440\u043e\u0447\u0438\u0435 \u043a\u043e\u0434\u044b \u043e\u0448\u0438\u0431\u043e\u043a (\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432) \u0438 \u0438\u0445 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435 POSIX. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0432 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f\u0445 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043e\u0431\u044b\u0447\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0438\u043c\u0438 \u043a\u043e\u0434\u044b \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u0438\u0445 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f. <\/p>\n<p>  \u041d\u0435\u0445\u0438\u0442\u0440\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u043a\u043e\u0434\u044b \u043e\u0448\u0438\u0431\u043e\u043a, \u0438\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u0430 \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f:   <\/p>\n<pre><code class=\"perl\">#!\/usr\/bin\/perl  use strict; use warnings;  use Errno;  foreach my $err (sort keys (%!)) {     $! = eval &quot;Errno::$err&quot;;     printf &quot;%20s %4d   %s\\n&quot;, $err, $! + 0, $! }<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u0442\u043e \u043e\u043d\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <b>errno<\/b> \u0432 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u044b\u0437\u043e\u0432 \u043f\u0440\u043e\u0448\u0451\u043b \u0443\u0441\u043f\u0435\u0448\u043d\u043e, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0438 \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <b>errno<\/b>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0435\u0451 \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0432 <code>0<\/code>.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"cpp\">\/* convert from UTF16 to UTF8 *\/ errno = 0;\t n_ret = iconv(icd, (char **) &p_src, &n_src, &p_dst, &n_dst);    \t if (n_ret == (size_t) -1) {     VJ_PERROR();     if (errno == E2BIG)           fprintf(stderr, &quot; Error : input conversion stopped due to lack of space in the output buffer\\n&quot;);     else if (errno == EILSEQ)           fprintf(stderr, &quot; Error : input conversion stopped due to an input byte that does not belong to the input codeset\\n&quot;);     else if (errno == EINVAL)           fprintf(stderr, &quot; Error : input conversion stopped due to an incomplete character or shift sequence at the end of the input buffer\\n&quot;); \/* clean the memory *\/        free(p_out_buf);     errno = 0;     n_ret = iconv_close(icd);           if (n_ret == (size_t) -1)           VJ_PERROR();     return (size_t) -1;  }<\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0432 <a href=\"https:\/\/www.freebsd.org\/cgi\/man.cgi?query=iconv&amp;apropos=0&amp;sektion=3&amp;manpath=FreeBSD+11.0-stable&amp;arch=default&amp;format=html\">\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/a> \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>iconv()<\/code> \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u044b, \u0447\u0435\u043c \u0432 <code>&lt;errno.h&gt;<\/code>. <\/p>\n<h3>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 errno<\/h3>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u043a\u043e\u0434 \u043e\u0448\u0438\u0431\u043a\u0438, \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e \u043d\u0435\u043c\u0443 \u0435\u0451 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, ISO C \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0446\u0435\u043b\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. <\/p>\n<h4><a href=\"https:\/\/en.wikipedia.org\/wiki\/C_string_handling\">&lt;stdio.h&gt;<\/a><\/h4>\n<p>  <code>void perror(const char *s);<\/code> <\/p>\n<p>  \u041f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0432 <b>stderr<\/b> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 <code>s<\/code>, \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u0435, \u043f\u0440\u043e\u0431\u0435\u043b \u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 <code>'\\n'<\/code>. <\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"cpp\">\/* \/\/  main.c \/\/  perror example \/\/ \/\/  Created by Ariel Feinerman on 23\/03\/17. \/\/  Copyright  2017 Feinerman Research, Inc. All rights reserved. *\/  #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;errno.h&gt;  int main(int argc, const char * argv[])  {     \/\/ Generate unique filename.     char *file_name = tmpnam((char[L_tmpnam]){0});         errno = 0;     FILE *file = fopen(file_name, &quot;rb&quot;);      if (file) {         \/\/ Do something useful.          fclose(file);     }     else {         perror(&quot;fopen() &quot;);     } \t     return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  <\/p>\n<h4><a href=\"https:\/\/en.wikipedia.org\/wiki\/C_string_handling\">&lt;string.h&gt;<\/a><\/h4>\n<p>  char* strerror(int errnum); <br \/>  \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 <code>errnum<\/code>. \u042f\u0437\u044b\u043a \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043b\u043e\u043a\u0430\u043b\u0438 (\u043d\u0435\u043c\u0435\u0446\u043a\u0438\u0439, \u0438\u0432\u0440\u0438\u0442 \u0438 \u0434\u0430\u0436\u0435 \u044f\u043f\u043e\u043d\u0441\u043a\u0438\u0439), \u043d\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439. <\/p>\n<pre><code class=\"cpp\">\/* \/\/  main.c \/\/  strerror example \/\/ \/\/  Created by Ariel Feinerman on 23\/03\/17. \/\/  Copyright  2017 Feinerman Research, Inc. All rights reserved. *\/  #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt;  #include &lt;errno.h&gt;  int main(int argc, const char * argv[])  {     \/\/ Generate unique filename.     char *file_name = tmpnam((char[L_tmpnam]){0});      errno = 0;     FILE *file = fopen(file_name, &quot;rb&quot;);     \/\/ Save error number.      errno_t error_num = errno; \t     if (file) {         \/\/ Do something useful.          fclose(file);     }     else {         char *errorbuf = strerror(error_num);         fprintf(stderr, &quot;Error message : %s\\n&quot;, errorbuf);     }          return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  <code>strerror()<\/code> \u043d\u0435 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0430\u044f \u0435\u044e \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u043e\u0439. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438\u043b\u0438 \u0432 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0451 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0435\u0441\u043b\u0438 \u0432\u044b \u0440\u0435\u0448\u0438\u0442\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0443, \u0438 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0438\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u043d\u043e\u0432\u044b\u043c \u043a\u043e\u0434\u043e\u043c, \u0432\u0441\u0435 \u043f\u0440\u0435\u0436\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u0438\u0431\u043e \u043e\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043e\u0434\u0438\u043d \u0431\u0443\u0444\u0435\u0440 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u043e\u043a. \u0412-\u0442\u0440\u0435\u0442\u044c\u0438\u0445, \u0435\u0451 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435. \u0412\u043f\u0440\u043e\u0447\u0435\u043c, \u0432 <a href=\"https:\/\/en.wikipedia.org\/wiki\/QNX\">QNX<\/a> \u043e\u043d\u0430 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0430 \u043a\u0430\u043a thread safe. <\/p>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043d\u043e\u0432\u043e\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435 <a href=\"https:\/\/en.wikipedia.org\/wiki\/C11_(C_standard_revision)\">ISO C11<\/a> \u0431\u044b\u043b\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u044b \u0434\u0432\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. <\/p>\n<p>  <code>size_t strerrorlen_s(errno_t errnum);<\/code><\/p>\n<p>  \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u043b\u0438\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0438 <code>errnum<\/code>. <\/p>\n<p>  <code>errno_t strerror_s(char *buf, rsize_t buflen, errno_t errnum);<\/code> <\/p>\n<p>  \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 <code>errnum<\/code> \u0432 \u0431\u0443\u0444\u0435\u0440 <code>buf<\/code> \u0434\u043b\u0438\u043d\u043e\u0439 <code>buflen<\/code>. <\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"cpp\">\/* \/\/  main.c \/\/  strerror_s example -- works nowhere \/\/ \/\/  Created by Ariel Feinerman on 23\/02\/17. \/\/  Copyright  2017 Feinerman Research, Inc. All rights reserved. *\/  #define __STDC_WANT_LIB_EXT1__ 1 #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt;  #include &lt;errno.h&gt;  int main(int argc, const char * argv[])  {     \/\/ Generate unique filename.     char *file_name = tmpnam((char[L_tmpnam]){0}); \t     errno = 0;     FILE *file = fopen(file_name, &quot;rb&quot;);     \/\/ Save error number.      errno_t error_num = errno;      if (file) {         \/\/ Do something useful.          fclose(file);     }     else { #ifdef __STDC_LIB_EXT1__     size_t error_len = strerrorlen_s(errno) + 1;     char error_buf[error_len];     strerror_s(error_buf, error_len, errno);     fprintf(stderr, &quot;Error message : %s\\n&quot;, error_buf); #endif     } \t     return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0445\u043e\u0434\u044f\u0442 \u0432 Annex K (Bounds-checking interfaces), \u0432\u044b\u0437\u0432\u0430\u0432\u0448\u0438\u0439 \u043c\u043d\u043e\u0433\u043e <a href=\"http:\/\/www.open-std.org\/jtc1\/sc22\/wg14\/www\/docs\/n1967.htm\">\u0441\u043f\u043e\u0440\u043e\u0432<\/a>. \u041e\u043d \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d \u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044e \u0438 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0438 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. <a href=\"https:\/\/en.wikipedia.org\/wiki\/Watcom_C\/C%2B%2B\">Open Watcom C\/C++<\/a> (Windows), <a href=\"https:\/\/code.google.com\/archive\/p\/slibc\">Slibc<\/a> (GNU libc) \u0438 <a href=\"https:\/\/sourceforge.net\/projects\/safeclib\">Safe C Library<\/a> (POSIX), \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0438 \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0440\u0435\u0434\u0430\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, <a href=\"https:\/\/www.embarcadero.com\/products\/rad-studio\">Embarcadero RAD Studio<\/a>, <a href=\"http:\/\/www.tenasys.com\/tenasys-products\/development-tools\/overview-sdk\">INtime RTOS<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/QNX\">QNX<\/a>. <\/p>\n<p>  \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442 <a href=\"http:\/\/pubs.opengroup.org\/onlinepubs\/9699919799\">POSIX.1-2008<\/a> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<p>  <code>char *strerror_l(int errnum, locale_t locale);<\/code><\/p>\n<p>  \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u043b\u043e\u043a\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 <code>errnum<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>locale<\/code>. \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0430 \u0432 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435. \u041d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432 <a href=\"https:\/\/en.wikipedia.org\/wiki\/MacOS\">Mac OS X<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/FreeBSD\">FreeBSD<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/NetBSD\">NetBSD<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/OpenBSD\">OpenBSD<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Solaris_(operating_system)\">Solaris<\/a> \u0438 \u043f\u0440\u043e\u0447\u0438\u0445 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u0438\u0445 UNIX. \u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432 Linux, <a href=\"https:\/\/en.wikipedia.org\/wiki\/MINIX_3\">MINIX 3<\/a> \u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Illumos\">Illumos<\/a> (OpenSolaris).<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440:   <\/p>\n<pre><code class=\"cpp\">\/*  \/\/  main.c  \/\/  strerror_l example \u2013 works on Linux, MINIX 3, Illumos  \/\/  \/\/  Created by Ariel Feinerman on 23\/03\/17.  \/\/  Copyright  2017 Feinerman Research, Inc. All rights reserved.  *\/  #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt;  #include &lt;errno.h&gt;  #include &lt;locale.h&gt;  int main(int argc, const char * argv[])  {     locale_t locale = newlocale(LC_ALL_MASK, &quot;fr_FR.UTF-8&quot;, (locale_t) 0);          if (!locale) {         fprintf(stderr, &quot;Error: cannot create locale.&quot;);         exit(EXIT_FAILURE);     }      \/\/ Generate unique filename.     char *file_name = tmpnam((char[L_tmpnam]){0}); \t     errno = 0;     FILE *file = fopen(tmpnam(file_name, &quot;rb&quot;);     \/\/ Save error number.      errno_t error_num = errno;      if (file) {         \/\/ Do something useful.          fclose(file);     }     else {         char *error_buf = strerror_l(errno, locale);         fprintf(stderr, &quot;Error message : %s\\n&quot;, error_buf);     } \t     freelocale(locale); \t     return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:  <\/p>\n<pre><code class=\"bash\">Error message : Aucun fichier ou dossier de ce type<\/code><\/pre>\n<p>  <code>int strerror_r(int errnum, char *buf, size_t buflen);<\/code><\/p>\n<p>  \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 <code>errnum<\/code> \u0432 \u0431\u0443\u0444\u0435\u0440 <code>buf<\/code> \u0434\u043b\u0438\u043d\u043e\u0439 <code>buflen<\/code>. \u0415\u0441\u043b\u0438 <code>buflen<\/code> \u043c\u0435\u043d\u044c\u0448\u0435 \u0434\u043b\u0438\u043d\u044b \u0441\u0442\u0440\u043e\u043a\u0438, \u043b\u0438\u0448\u043d\u0435\u0435 \u043e\u0431\u0440\u0435\u0437\u0430\u0435\u0442\u0441\u044f. \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0430 \u0432 \u043c\u043d\u043e\u0433\u043e\u0433\u043e\u0442\u043e\u0447\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435. \u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432\u043e \u0432\u0441\u0435\u0445 UNIX.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"cpp\">\/* \/\/  main.c \/\/  strerror_r POSIX example \/\/ \/\/  Created by Ariel Feinerman on 25\/02\/17. \/\/  Copyright  2017 Feinerman Research, Inc. All rights reserved. *\/  #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt;  #include &lt;errno.h&gt;  #define MSG_LEN 1024   int main(int argc, const char * argv[])  {     \/\/ Generate unique filename.     char *file_name = tmpnam((char[L_tmpnam]){0});          errno = 0;     FILE *file = fopen(file_name, &quot;rb&quot;);     \/\/ Save error number.      errno_t error_num = errno;\t \t     if (file) {         \/\/ Do something useful.         fclose(file);     }     else {         char error_buf[MSG_LEN];         errno_t error = strerror_r (error_num, error_buf, MSG_LEN); \t\t         switch (error) {             case EINVAL:                     fprintf (stderr, &quot;strerror_r() failed: invalid error code, %d\\n&quot;, error);                     break;             case ERANGE:                     fprintf (stderr, &quot;strerror_r() failed: buffer too small: %d\\n&quot;, MSG_LEN);             case 0:                     fprintf(stderr, &quot;Error message : %s\\n&quot;, error_buf);                     break;             default:                      fprintf (stderr, &quot;strerror_r() failed: unknown error, %d\\n&quot;, error);                     break;         }     }          return EXIT_SUCCESS; } <\/code><\/pre>\n<p>  \u0423\u0432\u044b, \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0430 <code>strerrorlen_s()<\/code> \u0432 POSIX \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u0438\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c \u043b\u0438\u0448\u044c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0443\u0442\u0451\u043c. \u041e\u0431\u044b\u0447\u043d\u043e 300 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0437\u0430 \u0433\u043b\u0430\u0437\u0430. <a href=\"https:\/\/en.wikipedia.org\/wiki\/GNU_C_Library\">GNU C Library<\/a> \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>strerror()<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0431\u0443\u0444\u0435\u0440 \u0434\u043b\u0438\u043d\u043e\u0439 \u0432 1024 \u0441\u0438\u043c\u0432\u043e\u043b\u0430. \u041d\u043e \u043c\u0430\u043b\u043e \u043b\u0438, \u0430 \u0432\u0434\u0440\u0443\u0433?<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"cpp\">\/*  \/\/  main.c  \/\/  strerror_r safe POSIX example  \/\/  \/\/  Created by Ariel Feinerman on 23\/03\/17.  \/\/  Copyright  2017 Feinerman Research, Inc. All rights reserved.  *\/  #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt;  #include &lt;errno.h&gt;  #define MSG_LEN 1024  #define MUL_FACTOR 2  int main(int argc, const char * argv[])  {     \/\/ Generate unique filename.     char *file_name = tmpnam((char[L_tmpnam]){0}); \t     errno = 0;     FILE *file = fopen(file_name, &quot;rb&quot;);     \/\/ Save error number.      errno_t error_num = errno; \t     if (file) {         \/\/ Do something useful.         fclose(file);     }     else {         errno_t error = 0;         size_t error_len = MSG_LEN;  \t\t         do {             char error_buf[error_len];             error = strerror_r (error_num, error_buf, error_len);             switch (error) {                     case 0:                             fprintf(stderr, &quot;File : %s\\nLine : %d\\nCurrent function : %s()\\nFailed function : %s()\\nError message : %s\\n&quot;, __FILE__, __LINE__, __func__, &quot;fopen&quot;, error_buf); \t                    break;                     case ERANGE:                              error_len *= MUL_FACTOR;                             break;                     case EINVAL:                              fprintf (stderr, &quot;strerror_r() failed: invalid error code, %d\\n&quot;, error_num);                             break;                     default:                             fprintf (stderr, &quot;strerror_r() failed: unknown error, %d\\n&quot;, error);                             break;             } \t\t\t         } while (error == ERANGE);     }          return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:  <\/p>\n<pre><code class=\"bash\">File : \/Users\/ariel\/main.c Line : 47 Current function : main() Failed function : fopen() Error message : No such file or directory<\/code><\/pre>\n<p>  <\/p>\n<h3>\u041c\u0430\u043a\u0440\u043e\u0441 <a href=\"http:\/\/en.cppreference.com\/w\/c\/error\/assert\">assert()<\/a><\/h3>\n<p>  <\/p>\n<h4><a href=\"https:\/\/en.wikipedia.org\/wiki\/Assert.h\">&lt;assert.h&gt;<\/a><\/h4>\n<p>  <code>void assert(expression)<\/code><\/p>\n<p>  \u041c\u0430\u043a\u0440\u043e\u0441, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0449\u0438\u0439 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <code>expression<\/code> (\u0435\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0447\u0438\u0441\u043b\u043e\u043c) \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0415\u0441\u043b\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f (<code>expression<\/code> \u0440\u0430\u0432\u043d\u043e \u043d\u0443\u043b\u044e), \u043e\u043d \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0432 <b>stderr<\/b> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>__FILE__<\/code>, <code>__LINE__<\/code>, <code>__func__<\/code> \u0438 <code>expression<\/code> \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>abort()<\/code>. <\/p>\n<pre><code class=\"cpp\">\/* \/\/  main.c \/\/  assert example \/\/ \/\/  Created by Ariel Feinerman on 23\/03\/17. \/\/  Copyright  2017 Feinerman Research, Inc. All rights reserved. *\/  #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;assert.h&gt;  #include &lt;math.h&gt;  int main(int argc, const char * argv[]) {     double x = -1.0;     assert(x &gt;= 0.0);     printf(&quot;sqrt(x) = %f\\n&quot;, sqrt(x));             return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:  <\/p>\n<pre><code class=\"bash\">Assertion failed: (x &gt;= 0.0), function main, file \/Users\/ariel\/main.c, line 17.<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u0430\u043a\u0440\u043e\u0441 <code>NDEBUG<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u043f\u0435\u0440\u0435\u0434 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c <code>&lt;assert.h&gt;<\/code>, \u0442\u043e <code>assert()<\/code> \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 <code>((void) 0)<\/code> \u0438 \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445. <\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"cpp\">\/* \/\/  main.c \/\/  assert_example \/\/ \/\/  Created by Ariel Feinerman on 23\/03\/17. \/\/  Copyright  2017 Feinerman Research, Inc. All rights reserved. *\/  #NDEBUG  #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;assert.h&gt;  #include &lt;math.h&gt;  int main(int argc, const char * argv[]) {     double x = -1.0;     assert(x &gt;= 0.0);     printf(&quot;sqrt(x) = %f\\n&quot;, sqrt(x));             return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:  <\/p>\n<pre><code class=\"bash\">sqrt(x) = nan<\/code><\/pre>\n<p>  <\/p>\n<h3>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 <a href=\"http:\/\/en.cppreference.com\/w\/c\/program\/atexit\">atexit()<\/a>, <a href=\"http:\/\/en.cppreference.com\/w\/c\/program\/exit\">exit()<\/a> \u0438 <a href=\"http:\/\/en.cppreference.com\/w\/c\/program\/abort\">abort()<\/a><\/h3>\n<p>  <\/p>\n<h4><a href=\"http:\/\/pubs.opengroup.org\/onlinepubs\/9699919799\">&lt;stdlib.h&gt;<\/a><\/h4>\n<p>  <code>int atexit(void (*func)(void));<\/code> <\/p>\n<p>  \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u043f\u0440\u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435, \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u0438\u0445 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e 32 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. <\/p>\n<p>  <code>_Noreturn void exit(int exit_code);<\/code> <\/p>\n<p>  \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432 \u0441\u0440\u0435\u0434\u0443 \u0447\u0438\u0441\u043b\u043e <code>exit_code<\/code>. ISO C \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0432\u0441\u0435\u0433\u043e \u0442\u0440\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f: <code>0<\/code>, <code><a href=\"http:\/\/en.cppreference.com\/w\/c\/program\/EXIT_status\">EXIT_SUCCESS<\/a><\/code> \u0438 <code><a href=\"http:\/\/en.cppreference.com\/w\/c\/program\/EXIT_status\">EXIT_FAILURE<\/a><\/code>. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0447\u0435\u0440\u0435\u0437 <code>atexit()<\/code>, \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u0442\u043e\u043a\u0438 \u0432\u0432\u043e\u0434\u0430 \u2014 \u0432\u044b\u0432\u043e\u0434\u0430, \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u044e\u0442\u0441\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \u0441\u0440\u0435\u0434\u0443. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>exit()<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 <code><a href=\"http:\/\/en.cppreference.com\/w\/c\/language\/main_function\">main()<\/a><\/code> \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 return \u0438\u043b\u0438 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0438 \u043a\u043e\u043d\u0446\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. <\/p>\n<p>  \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e <code>exit()<\/code> \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 <code>main()<\/code>, \u043d\u043e \u0438 \u0438\u0437 \u043b\u044e\u0431\u043e\u0439 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0435\u0441\u043b\u0438 \u0432 \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u043e\u0441\u044c (\u0438\u043b\u0438 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u043e\u0441\u044c) \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0442\u0435\u0440\u044f\u0435\u0442 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043c\u044b\u0441\u043b. \u041f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043f\u0440\u0438\u0451\u043c (early exit) \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0434\u0435\u043c\u043e\u043d\u043e\u0432, \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0443\u0442\u0438\u043b\u0438\u0442 \u0438 \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432. \u0412 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445 \u0441 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c <code>exit()<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u0435 \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043f\u0443\u043d\u043a\u0442\u0430 \u043c\u0435\u043d\u044e. <\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"cpp\">\/* \/\/  main.c \/\/  exit example \/\/ \/\/  Created by Ariel Feinerman on 17\/03\/17. \/\/  Copyright  2017 Feinerman Research, Inc. All rights reserved. *\/  #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;math.h&gt;  void third_2(void)  {     printf(&quot;third #2\\n&quot;);          \/\/ Does not print. }  void third_1(void)  {     printf(&quot;third #1\\n&quot;);          \/\/ Does not print. }  void second(double num)  {     printf(&quot;second : before exit()\\n&quot;);\t\/\/ Prints.          if ((num &lt; 1.0f) && (num &gt; -1.0f)) {         printf(&quot;asin(%.1f) = %.3f\\n&quot;, num, asin(num));         exit(EXIT_SUCCESS);     }     else {         fprintf(stderr, &quot;Error: %.1f is beyond the range [-1.0; 1.0]\\n&quot;, num);         exit(EXIT_FAILURE);     }          printf(&quot;second : after exit()\\n&quot;);\t\/\/ Does not print. }  void first(double num)  {     printf(&quot;first : before second()\\n&quot;)     second(num);     printf(&quot;first : after second()\\n&quot;);          \/\/ Does not print. }  int main(int argc, const char * argv[])  {     atexit(third_1); \/\/ Register first handler.      atexit(third_2); \/\/ Register second handler.          first(-3.0f);          return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:  <\/p>\n<pre><code class=\"bash\">first : before second() second : before exit() Error: -3.0 is beyond the range [-1.0; 1.0] third #2 third #1<\/code><\/pre>\n<p>  <code>_Noreturn void abort(void);<\/code><\/p>\n<p>  \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0430\u0432\u0430\u0440\u0438\u0439\u043d\u043e\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0435\u0441\u043b\u0438 \u0441\u0438\u0433\u043d\u0430\u043b \u043d\u0435 \u0431\u044b\u043b \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0447\u0435\u043d \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432. \u0412\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u043d\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u044e\u0442\u0441\u044f, \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439. \u0421\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 abort() \u0438 <code>exit(EXIT_FAILURE)<\/code> \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0441\u0438\u0433\u043d\u0430\u043b <code>SIGABRT<\/code>, \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0438\u0442\u044c \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043d\u0443\u0436\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u0435\u0440\u0435\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0430\u043c\u043f \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b <a href=\"https:\/\/en.wikipedia.org\/wiki\/Core_dump\">(core dump file<\/a>), \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u044b. \u041f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0432 \u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a\u0435 \u043e\u043d \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b <code>SIGABRT<\/code> \u0438 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0447\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0432 \u043e\u0442\u043b\u0430\u0434\u043a\u0435. <\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"cpp\">\/* \/\/  main.c \/\/  abort example \/\/ \/\/  Created by Ariel Feinerman on 17\/02\/17. \/\/  Copyright  2017 Feinerman Research, Inc. All rights reserved. *\/  #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;math.h&gt;  void third_2(void)  {     printf(&quot;third #2\\n&quot;);          \/\/ Does not print. }  void third_1(void)  {     printf(&quot;third #1\\n&quot;);          \/\/ Does not print. }  void second(double num)  {     printf(&quot;second : before exit()\\n&quot;);\t\/\/ Prints.          if ((num &lt; 1.0f) && (num &gt; -1.0f)) {         printf(&quot;asin(%.1f) = %.3f\\n&quot;, num, asin(num));         exit(EXIT_SUCCESS);     }     else {         fprintf(stderr, &quot;Error: %.1f is beyond the range [-1.0; 1.0]\\n&quot;, num);         abort();     }          printf(&quot;second : after exit()\\n&quot;);\t\/\/ Does not print. }  void first(double num)  {     printf(&quot;first : before second()\\n&quot;);     second(num);     printf(&quot;first : after second()\\n&quot;);          \/\/ Does not print. }  int main(int argc, const char * argv[])  {     atexit(third_1); \/\/ register first handler      atexit(third_2); \/\/ register second handler          first(-3.0f);          return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:  <\/p>\n<pre><code class=\"bash\">first : before second() second : before exit() Error: -3.0 is beyond the range [-1.0; 1.0] Abort trap: 6<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434 \u0432 \u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a\u0435:  <\/p>\n<pre><code class=\"bash\">$ lldb abort_example  (lldb) target create &quot;abort_example&quot; Current executable set to 'abort_example' (x86_64). (lldb) run Process 22570 launched: '\/Users\/ariel\/abort_example' (x86_64) first : before second() second : before exit() Error: -3.0 is beyond the range [-1.0; 1.0] Process 22570 stopped * thread #1: tid = 0x113a8, 0x00007fff89c01286 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT     frame #0: 0x00007fff89c01286 libsystem_kernel.dylib`__pthread_kill + 10 libsystem_kernel.dylib`__pthread_kill: -&gt;  0x7fff89c01286 &lt;+10&gt;: jae    0x7fff89c01290            ; &lt;+20&gt;     0x7fff89c01288 &lt;+12&gt;: movq   %rax, %rdi     0x7fff89c0128b &lt;+15&gt;: jmp    0x7fff89bfcc53            ; cerror_nocancel     0x7fff89c01290 &lt;+20&gt;: retq    (lldb) <\/code><\/pre>\n<p>  \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>abort()<\/code>. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0444\u0430\u0439\u043b\u0430 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430. \u041b\u044e\u0431\u044b\u0435 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0443\u0441\u0443\u0433\u0443\u0431\u0438\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e. \u0415\u0441\u043b\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u0431\u0440\u043e\u0441 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432\u0432\u043e\u0434\u0430 \u2014 \u0432\u044b\u0432\u043e\u0434\u0430, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u0435\u0449\u0451 \u043d\u0435\u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0430\u043c\u044b\u043c \u043b\u0443\u0447\u0448\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043c\u043f \u0438 \u043c\u0433\u043d\u043e\u0432\u0435\u043d\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. <\/p>\n<p>  \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0436\u0435 \u043d\u0435\u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u043d\u0435 \u0441\u043c\u043e\u0433\u043b\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0444\u0430\u0439\u043b, \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0432\u044b\u0439\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 <code>exit()<\/code>.<\/p>\n<h3>\u0424\u0443\u043d\u043a\u0446\u0438\u0438 <a href=\"http:\/\/en.cppreference.com\/w\/c\/program\/setjmp\">setjmp()<\/a> \u0438 <a href=\"http:\/\/en.cppreference.com\/w\/c\/program\/longjmp\">longjmp()<\/a><\/h3>\n<p>  \u0412\u043e\u0442 \u043c\u044b \u0438 \u043f\u043e\u0434\u043e\u0448\u043b\u0438 \u043a \u0441\u0430\u043c\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443 \u2013 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c \u043d\u0435\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432. <code>setjmp()<\/code> \u0438 <code>longjmp()<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 <b>goto<\/b>, \u043d\u043e \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043d\u0435\u0433\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0435\u0440\u0435\u043f\u0440\u044b\u0433\u0438\u0432\u0430\u0442\u044c \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0435 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0432\u0441\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0430 \u043d\u0435 \u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. <\/p>\n<h4><a href=\"https:\/\/en.wikipedia.org\/wiki\/Setjmp.h\">&lt;setjmp.h&gt;<\/a><\/h4>\n<p>  <code>int setjmp(jmp_buf env);<\/code><\/p>\n<p>  \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b (\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u044b \u043c\u0438\u043a\u0440\u043e\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0438 \u043f\u0440\u043e\u0447\u0435\u0435) \u0432 <code>env<\/code>. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>0<\/code>, \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u0430 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u043b\u0438 <code>value<\/code>, \u0435\u0441\u043b\u0438 \u0438\u0437 <code>longjmp()<\/code>. <\/p>\n<p>  <code>void longjmp(jmp_buf env, int value);<\/code> <\/p>\n<p>  \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u0437 <code>env<\/code>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <code>setjmp()<\/code> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0435\u0439 <code>value<\/code>.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"cpp\">\/* \/\/  main.c \/\/  setjmp simple \/\/ \/\/  Created by Ariel Feinerman on 18\/02\/17. \/\/  Copyright  2017 Feinerman Research, Inc. All rights reserved. *\/  #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;setjmp.h&gt;  static jmp_buf buf;  void second(void)  {     printf(&quot;second : before longjmp()\\n&quot;);\t\/\/ prints     longjmp(buf, 1);\t\t\t\t\t\t\/\/ jumps back to where setjmp was called \u2013 making setjmp now return 1     printf(&quot;second : after longjmp()\\n&quot;);\t\/\/ does not prints \t     \/\/ &lt;- Here is the point that is never reached. All impossible cases like your own house in Miami, your million dollars, your nice girl, etc. }  void first(void)  {     printf(&quot;first : before second()\\n&quot;);     second();     printf(&quot;first : after second()\\n&quot;);          \/\/ does not print }  int main(int argc, const char * argv[])  {     if (!setjmp(buf))         first();                \/\/ when executed, setjmp returned 0     else                        \/\/ when longjmp jumps back, setjmp returns 1         printf(&quot;main\\n&quot;);       \/\/ prints          return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:  <\/p>\n<pre><code class=\"bash\">first : before second() second : before longjmp() main<\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>setjmp()<\/code> \u0438 <code>longjmp<\/code>() \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439. \u0412\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u0430\u0445 \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Perl\">Perl<\/a>) \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0447\u0435\u0440\u0435\u0437 \u043d\u0438\u0445. <\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440:  <\/p>\n<pre><code class=\"cpp\">\/* \/\/  main.c \/\/  exception simple \/\/ \/\/  Created by Ariel Feinerman on 18\/02\/17. \/\/  Copyright  2017 Feinerman Research, Inc. All rights reserved. *\/  #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;math.h&gt;  #include &lt;setjmp.h&gt;  #define str(s) #s  static jmp_buf buf;  typedef enum {     NO_EXCEPTION    = 0,     RANGE_EXCEPTION = 1,     NUM_EXCEPTIONS } exception_t;  static char *exception_name[NUM_EXCEPTIONS] = { \t     str(NO_EXCEPTION),     str(RANGE_EXCEPTION) };  float asin_e(float num)  {     if ((num &lt; 1.0f) && (num &gt; -1.0f)) {         return asinf(num);     }\t     else {         longjmp(buf, RANGE_EXCEPTION);        \/\/ | @throw       } }  void do_work(float num)  {     float res = asin_e(num);     printf(&quot;asin(%f) = %f\\n&quot;, num, res);          }  int main(int argc, const char * argv[])  {     exception_t exc = NO_EXCEPTION;     if (!(exc = setjmp(buf))) {        \/\/ |\t         do_work(-3.0f);                \/\/ | @try     }                                  \/\/ |     else {                                                                               \/\/ |          fprintf(stderr, &quot;%s was hadled in %s()\\n&quot;, exception_name[exc], __func__);       \/\/ | @catch     }                                                                                    \/\/ |  \t     return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:  <\/p>\n<pre><code class=\"bash\">RANGE_EXCEPTION was hadled in main()<\/code><\/pre>\n<p>  \u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u0424\u0443\u043d\u043a\u0446\u0438\u0438 <code>setjmp()<\/code> \u0438 <code>longjmp<\/code>() \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u0438 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u043c \u043a\u043e\u0434\u0435 \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f. \u0418\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0443\u0445\u0443\u0434\u0448\u0430\u0435\u0442 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0435\u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u044b\u043c \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u044b\u0433\u043d\u0438\u0442\u0435 \u043d\u0435 \u0432\u043d\u0438\u0437 \u043f\u043e \u0441\u0442\u0435\u043a\u0443 \u2013 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u0430 \u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u0443\u044e, \u0443\u0436\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0432\u0448\u0443\u044e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435? <\/p>\n<h3>\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f<\/h3>\n<p>  <\/p>\n<ul>\n<li>\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 ISO\/IEC C (<a href=\"https:\/\/en.wikipedia.org\/wiki\/C89\">89<\/a>\/<a href=\"https:\/\/en.wikipedia.org\/wiki\/C99\">99<\/a>\/<a href=\"https:\/\/en.wikipedia.org\/wiki\/C11_(C_standard_revision)\">11<\/a>)<\/li>\n<li><a href=\"http:\/\/www.unix.org\/version4\">Single UNIX Specifcation, Version 4, 2016 Edition<\/a><\/li>\n<li><a href=\"http:\/\/pubs.opengroup.org\/onlinepubs\/9699919799\">The Open Group Base Specifcations Issue 7, 2016 Edition (POSIX.1-2008)<\/a><\/li>\n<li><a href=\"https:\/\/www.securecoding.cert.org\/confluence\/display\/c\/SEI+CERT+C+Coding+Standard\">SEI CERT C Coding Standard<\/a><\/li>\n<li>c\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0441\u0440\u0435\u0434\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/li>\n<li>\u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Man_page\">man pages<\/a>)<\/li>\n<li>\u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b (\/usr\/include)<\/li>\n<li>\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0442\u0435\u043a\u0441\u0442\u044b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 (<a href=\"https:\/\/en.wikipedia.org\/wiki\/C_standard_library\">C Standard Library<\/a>)<\/li>\n<\/ul>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/324642\/\"> https:\/\/habrahabr.ru\/post\/324642\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/9f0\/658\/511\/9f0658511b7b48f7b67b68f6174c12f2.jpg\"\/><\/p>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u041e\u0448\u0438\u0431\u043a\u0438, \u0443\u0432\u044b, \u043d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e\u0435 \u043c\u0435\u0441\u0442\u043e \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438. \u0418 \u0435\u0441\u043b\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0442\u043e \u043e\u0448\u0438\u0431\u043e\u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 (<a href=\"https:\/\/en.wikipedia.org\/wiki\/C_standard_library\">C Standard Library<\/a>) \u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/POSIX\">POSIX<\/a>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043e\u0448\u0438\u0431\u043e\u043a.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-284324","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=284324"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284324\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}