简体   繁体   中英

How are function arguments passed in C?

The only thing that I know about the mechanism of how C passes values is that it is done either through a register or the stack.

Register or Stack? Exactly how?

Both. And the conventions will vary by platform.

On x86, values are usually passed by stack. On x64, passing by register is preferred.

In all cases, if you have too many parameters, some will have to be passed by stack.

Refer to x86 calling conventions

Typically (some compilers will do it differently as pointed out) for normal function calls they are passed on the stack. That is usually it is a series of push instructions that just put the data onto the stack.

There are special cases such as system calls where parameters get passed via assembly instructions and registers. In hardware cases they are passed via registers or even certain interrupt signals which consequently write to registers.

On architectures with high numbers of registers they are usually passed via registers such as some RISC and 64 bit architectures.

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