MS Visual C ++: When Should You Care About Using Call Conventions?

In C / C ++ (in particular, I use MSVS), in what situation would you ever need to worry about defining a calling convention to define a function? Are they always important? Do you have the opportunity to choose the optimal agreement if necessary (for example, fastcall, etc.)?

Perhaps my understanding is missing, but I just don’t see when there will be a case when the programmer will need to take care of things similar to the order that arguments are pushed onto the stack, etc. I also don’t understand why compiler optimization will not be able to choose which circuit will work best for this particular function. Any knowledge that could give me would be wonderful. Thanks!

+8
c ++ c calling-convention
source share
2 answers

In general terms, the calling convention is important when you integrate code that is compiled by different compilers. For example, if you publish a DLL that will be used by your clients, you will want to make sure that all functions that you export have a consistent expected calling convention.

You are right that, within a single program, the compiler can usually choose which calling convention to use for each function (and the rules are usually pretty simple).

+10
source share

You do not need to worry about 64-bit applications, since there is only one calling convention.

You need to pay attention to 32-bit applications in the following cases:

  • You interact with third-party libraries, and the headers for these libraries have not announced the correct calling convention.
  • You are creating a library or DLL for someone else. You need to make a call decision so that the other code uses the correct calling convention when calling your code.
+6
source share

All Articles