计算机相关试题

本文详细解释了GCC编译器如何按逆序推送参数至栈中,即最后一个参数最先被推送。这种做法使得函数能够通过定位首个参数来确定其余参数的数量及类型,如printf函数即依赖这一特性来确定其格式字符串及其他参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

gcc pushes the arguments in a particular order. What is the order and why?

 

Answer: gcc pushes arguments in reverse order, last argument first. Because the stack grows down on the x86 (and PDP-11), this means that the first argument (last one pushed) will have the lowest address in memory, just above the function's return address. This way, the called function can find its first argument without knowing exactly how many and what types of other arguments it was called with. Knowing the location and type of the first argument, the function can then locate the second argument (if there is one), and so on. The printf()function depends on this property because it uses its first argument (the format string) to determine how many and what types of additional arguments it was called with.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值