简体   繁体   中英

How to declare a function with variable arguments to be stdcall?

Now I am designing a function f(index,...) which will call #index entry in a function array passing the rest of parameters. If you see the function array as a service list, f acts like a service distributer.

f is written in assembly. It pops the first parameter index then calculates the corresponding target function address and jmp to it.

If I pass n parameters to f , the stack just holds n-1 ones when returning from the target function, because index was popped midway. For this reason, I cannot use cdecl convention, or the caller will clean the stack for n parameters by mistake.

stdcall should works. But the problem is that, since f has variable arguments , gcc seems __attribute__((stdcall)) f(index,...) unreasonable and reverts it back to cdecl .

So please could any one tell me how to declare f to be stdcall ?

I don't think using stdcall would solve your problem, since you would have to restore the stack anyway for your function to find the return address on the stack.

Rather than popping index from the stack, just leave it there. And either modify your target functions to ignore the first parameter, or move all the other parameters one position to the left before calling target function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM