Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Curious...I can reproduce the problem on Mac OS X 10.9 Mavericks with GCC 4.8.2 and with Clang.</p> <p>POSIX says that some functions that fail will set <code>errno</code> (and <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html" rel="nofollow"><code>fork()</code></a> is one of those functions), but does not say that functions that succeed will not set <code>errno</code>. For example, on Solaris, many standard I/O functions set <code>errno</code> if the output stream is not a terminal. However, resetting <code>errno = 0;</code> after the <code>printf()</code> doesn't alter the behaviour on Mac OS X.</p> <h3>POSIX 2008 (System Interfaces — General Information: 3. <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_03" rel="nofollow">Error numbers</a>):</h3> <blockquote> <p>Some functions provide the error number in a variable accessed through the symbol <code>errno</code>, defined by including the <code>&lt;errno.h&gt;</code> header. The value of <code>errno</code> should only be examined when it is indicated to be valid by a function's return value. No function in this volume of POSIX.1-2008 shall set <code>errno</code> to zero. For each thread of a process, the value of <code>errno</code> shall not be affected by function calls or assignments to <code>errno</code> by other threads.</p> </blockquote> <p>If <code>fork()</code> failed, then <code>errno</code> would be set to indicate the failure. When it succeeds, it is not technically valid to inspect <code>errno</code>. And this is a demonstration of why.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload