What does a “CALLBACK” declaration in C do?

后端 未结 4 1955
Happy的楠姐
Happy的楠姐 2020-12-01 18:47

I was looking through some code from the SDL library and came across a function declared like this:

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wPar         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 19:42

    Short roundup from Raymond Chen's Blog:

    The great thing about calling conventions on the x86 platform is that there are so many to choose from!

    C calling convention (__cdecl)

    The C calling convention is constrained because it allows the use of functions with a variable number of parameters. It pretty much requires that the stack be caller-cleaned and that the parameters be pushed right to left, so that the first parameter is at a fixed position relative to the top of the stack. In summary: Caller cleans the stack, parameters pushed right to left.

    Pascal calling convention (__pascal)

    Pascal does not support functions with a variable number of parameters, so it can use the callee-clean convention. Parameters are pushed from left to right. Nearly all Win16 functions are exported as Pascal calling convention. The callee-clean convention saves three bytes at each call point, with a fixed overhead of two bytes per function. It was also fractionally faster. On Win16, saving a few hundred bytes and a few cycles was a big deal. Note: The Fortran calling convention (__fortran) is the same as the Pascal calling convention

提交回复
热议问题