c++ - stdcall and cdecl -


There are two types of calling summons - stdcall and cdecl <

itemprop = "text">

(among others) / Strong>. I have some questions on them:

  1. When a cdecl function is called, how does a collar know that it should free the stack? On the call site, does the caller know that the function is called a CDACL or a static function? how does it work ? How does the collar know if it should empty the stack or not? Or this linkers responsibility
  2. A function which stdcall is declared as a function (which is a calling conference in the form of cdecl), or vice versa, would this be unfair?
  3. In general, can we say which calls will be faster - CDECL or pediatric?

.

(1) After calling the caller function "knows" to clean the stack because the compiler knows the function of the calling conference and prepares the necessary code.

> __stdcall StdcallFunc () {} Zero __cdecl zero CdeclFunc () {// compiler knows that StdcallFunc () uses __stdcall // conference at this point, then this pile cleansing Generates appropriate binary // for StdcallFunc (); }

, like this:

  LRESULT MyWndProc (HWND hwnd, uint message, wParam wParam, lParam lParam); // ... // Compiler usually complains but this cast is here ... windowClass.lpfnWndProc = reinterpret_cast & lt; Wndproc & gt; (& MyWndProc);  

Lots of code samples go wrong. It is not too strange that it should have been done like this:

  // callback __stdcall LRESULT callback MyWndProc (HWND hwnd, uint message wParam wParam, lParam lParam) is #define'd; // ... windowClass.lpfnWndProc = and MyWndProc; However, assuming the programmer does not ignore compiler errors, the compiler will generate the necessary code to clean the stack, because the calling conventions of the included function will be known. / P> 

(2) Both ways should work in fact, this is often the least code that connects to the Windows API, because more.

(3) There should be no real performance differences between the two.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -