title: Differenence among open(), _open(), and fopen() with regard to MSVC compiler?
body: <p>I see these 3 functions are all related to opening a file.</p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/ms235491(v=vs.120).aspx" rel="nofollow noreferrer">open</a>:</p>
  
  <blockquote>
    <p><strong>This POSIX function is deprecated.</strong> Use the ISO C++ conformant _open
    instead.</p>
  </blockquote>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/z0kc8e3z(v=vs.120).aspx" rel="nofollow noreferrer">_open</a>:</p>
  
  <blockquote>
    <p>Opens a file. These functions are deprecated because more-secure
    versions are available; see _sopen_s, _wsopen_s.</p>
  </blockquote>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/yeby3zcb(v=vs.120).aspx" rel="nofollow noreferrer">fopen</a>:</p>
  
  <blockquote>
    <p>Opens a file. More-secure versions of these functions that perform
    additional parameter validation and return error codes are available;
    see fopen_s, _wfopen_s.</p>
  </blockquote>
  
  <p>So, why there are three of them? When to use which? I thought POSIX is good but why MSDN says the POSIX version of <code>open</code> is deprecated? And is there any <strong>naming convention</strong> related to the leading underscore so I can pick the right function based its first looking?</p>
  
  <p>And when I am looking into the <a href="https://github.com/acpica/acpica/" rel="nofollow noreferrer">ACPICA code</a>, I see below code:
  It seems the <code>_XXX</code> version can disable some <strong>MS language extensions</strong>, what exactly are these extensions?</p>
  
  <pre><code>/*
   * Map low I/O functions for MS. This allows us to disable MS language
   * extensions for maximum portability.
   */
  #define open            _open
  #define read            _read
  #define write           _write
  #define close           _close
  #define stat            _stat
  #define fstat           _fstat
  #define mkdir           _mkdir
  #define snprintf        _snprintf
  #if _MSC_VER &lt;= 1200 /* Versions below VC++ 6 */
  #define vsnprintf       _vsnprintf
  #endif
  #define O_RDONLY        _O_RDONLY
  #define O_BINARY        _O_BINARY
  #define O_CREAT         _O_CREAT
  #define O_WRONLY        _O_WRONLY
  #define O_TRUNC         _O_TRUNC
  #define S_IREAD         _S_IREAD
  #define S_IWRITE        _S_IWRITE
  #define S_IFDIR         _S_IFDIR
  </code></pre>
  
  <h2>ADD 1</h2>
  
  <p>It seems the single underscore prefix <code>_XXX</code> is a Microsoft convention. Such as <a href="https://msdn.microsoft.com/en-us/library/0b98s6w8.aspx" rel="nofollow noreferrer">_DEBUG</a>, <a href="https://msdn.microsoft.com/en-us/library/5at7yxcs.aspx" rel="nofollow noreferrer">_CrtSetDbgFlag</a>, and the aforementioned <a href="https://msdn.microsoft.com/en-us/library/z0kc8e3z(v=vs.120).aspx" rel="nofollow noreferrer">_open</a>. Some quote from the <a href="https://msdn.microsoft.com/en-us/library/2e6a4at9.aspx" rel="nofollow noreferrer">MSDN</a>:</p>
  
  <blockquote>
    <p>In Microsoft C++, identifiers with two leading underscores are
    reserved for compiler implementations. Therefore, the Microsoft
    convention is to precede Microsoft-specific keywords with double
    underscores. These words cannot be used as identifier names.</p>
    
    <p>Microsoft extensions are enabled by default. To ensure that your
    programs are fully portable, you can disable Microsoft extensions by
    specifying the ANSI-compatible /Za command-line option (compile for
    ANSI compatibility) during compilation. When you do this,
    Microsoft-specific keywords are disabled.</p>
    
    <p>When Microsoft extensions are enabled, you can use the
    Microsoft-specific keywords in your programs. For ANSI compliance,
    these keywords are prefaced by a <strong>double underscore</strong>. For backward
    compatibility, <strong>single-underscore</strong> versions of all the
    double-underscored keywords except __except, __finally, __leave, and
    __try are supported. In addition, __cdecl is available with no leading underscore.</p>
    
    <p>The __asm keyword replaces C++ asm syntax. asm is reserved for
    compatibility with other C++ implementations, but not implemented. Use
    __asm.</p>
    
    <p>The __based keyword has limited uses for 32-bit and 64-bit target
    compilations.</p>
  </blockquote>
  
  <p>Though according to above quote, <code>__int64</code> and <code>_int64</code> should both work, but Visual Studio provide NO syntax highlight for <code>_int64</code>. But <code>_int64</code> can compile, too.</p>
  
  <h2>ADD 2</h2>
  
  <p><a href="https://stackoverflow.com/questions/11579095/why-in-msvc-we-have-snprintf-while-other-compilers-allows-snprintf">snprintf() and _snprintf()</a></p>