Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The Single UNIX Specification requires the existence of <a href="http://pubs.opengroup.org/onlinepubs/7908799/xsh/unistd.h.html"><code>unistd.h</code></a>, which can tell you the POSIX version (via the <code>_POSIX_VERSION</code> macro).</p> <p><em>But how can you include <code>unistd.h</code> if you don't know yet that you are in fact compiling on a UNIX?</em></p> <p>That is where <a href="http://gcc.gnu.org/onlinedocs/cpp/System_002dspecific-Predefined-Macros.html">this GCC document</a> comes handy. According to it, testing for the presence, or evaluation-to-true of <code>__unix__</code> should tell you that the system is a UNIX. So:</p> <pre><code>#ifdef __unix__ /* Yes it is a UNIX because __unix__ is defined. */ #include &lt;unistd.h&gt; /* You can find out the version with _POSIX_VERSION. .. .. */ #endif </code></pre> <p><code>__unix__</code> is not defined on Mac OS X, so to account for that, you could instead do:</p> <pre><code>#if defined (__unix__) || (defined (__APPLE__) &amp;&amp; defined (__MACH__)) </code></pre> <p>To get a list of system specific predefined macros on your system, you may execute:</p> <pre><code>cpp -dM /dev/null </code></pre> <p>For example, my GNU/Linux system also additionally defines <code>__linux__</code> and <code>__gnu_linux__</code> apart from <code>__unix__</code> and a bunch of other stuff.</p> <hr> <p>Another useful document that you must look at is <a href="http://sourceforge.net/apps/mediawiki/predef/index.php?title=Operating_Systems#UNIX_Environment">this Wiki</a>.</p> <p>It <a href="http://sourceforge.net/apps/mediawiki/predef/index.php?title=Standards#Unix_Standards">goes on to present a way of detecting the presence and version of POSIX</a> in a way similar to the one I described above.</p> <hr> <p><strong>EDIT:</strong> Since you really want to do all this because you want to decide which directory separator to use, look at <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx">this URL</a>. It says:</p> <blockquote> <p><strong>Note</strong> File I/O functions in the Windows API convert "/" to "\" as part of converting the name to an NT-style name, except when using the "\?\" prefix as detailed in the following sections.</p> </blockquote> <p>I don't program on Windows, or know <s>much</s> anything about it, so I can't say I've banked on this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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