title: __cdecl or __stdcall on Windows?
body: <p>I'm currently developing a C++ library for Windows which will be distributed as a DLL. My goal is to maximize binary interoperability; more precisely, the functions in my DLL must be usable from code compiled with multiple versions of MSVC++ and MinGW without having to recompile the DLL. However, I'm confused about which calling convention is best, <a href="http://msdn.microsoft.com/en-us/library/zkwh89ks.aspx" rel="noreferrer"><code>cdecl</code></a> or <a href="http://msdn.microsoft.com/en-us/library/zxk0tw93.aspx" rel="noreferrer"><code>stdcall</code></a>.</p>
  <p>Sometimes I hear statements like &quot;the C calling convention is the only one guaranteed to be the same accross compilers&quot;, which contrasts with statements like &quot;<a href="http://en.wikipedia.org/wiki/X86_calling_conventions#cdecl" rel="noreferrer">There are some variations in the interpretation of <code>cdecl</code>, particularly in how to return values</a>&quot;. This doesn't seem to stop certain library developers (like <a href="http://www.mega-nerd.com/libsndfile/" rel="noreferrer">libsndfile</a>) to use the C calling convention in the DLLs they distribute, without any visible problems.</p>
  <p>On the other hand, the <code>stdcall</code> calling convention seems to be well-defined. From what I've been told, all Windows compilers are basically required to follow it because it's the convention used for Win32 and COM. This is based on the assumption that a Windows compiler without Win32/COM support would not be very useful. A lot of code snippets posted on forums declare functions as <code>stdcall</code> but I can't seem to find one single post which clearly explains <em>why</em>.</p>
  <p>There's too much conflicting information out there, and every search I run gives me different answers which doesn't really help me decide between the two. I'm searching for a clear, detailed, argumented explanation as to why I should choose one over the other (or why the two are equivalent).</p>
  <p>Note that this question not only applies to &quot;classic&quot; functions, but also to virtual member function calls, since most client code will interface with my DLL through &quot;interfaces&quot;, pure virtual classes (following patterns described e.g. <a href="https://stackoverflow.com/questions/232926/how-to-make-consistent-dll-binaries-across-vs-versions/232959#232959">here</a> and <a href="http://chadaustin.me/cppinterface.html" rel="noreferrer">there</a>).</p>