title: Calling convention to use for max. portability between x86 systems
body: <p>I am working on a set of self-contained x86 assembly routines that I would like to make available to C programs on systems below:</p>
  <ul>
  <li>Linux 64-bit only</li>
  <li>Windows 32-bit and 64-bit</li>
  <li>(Good to have ultimately, Mac 64-bit, but this is not clear as Apple appear to be on their way to drop x86 in favour of ARM)</li>
  </ul>
  <p>I use LLVM in some other capacity already and it is almost certain that I would use clang rather than gcc although I can envisage a situation of someone's wanting to compile the whole of it using gcc. The assembler will be NASM.</p>
  <p>I develop both the routines and a C library that exposes them to users, i.e. everything is under my control and I can design everything as needed.</p>
  <p>I expect that some users will actually use C++ but they will still link to the C library - that is, not with the assembly routines directly.</p>
  <p>As I am new to assembly, I am in the process of discovering a wonderful maze of various calling conventions spread across systems, compilers, vendors, calling variants and languages. I cannot say that it does not make for interesting reads sometimes but I cannot say either that it is not confusing to beginners.</p>
  <p>My take after reading up on it all is that at the end of the day I can simply start with cdecl for maximum portability in the initial version and then think about special casing to cover other conventions if needs arise - depending on what the routines actually do I may make things faster by using other conventions in specific cases.</p>
  <p>But initially, as I would like to have something that works correctly and then optimise it even further - is it correct to say that settling on <strong>cdecl</strong> will offer maximum portability across the systems that I listed? Thank you.</p>