计算机相关试题

 

 

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.

你可能感兴趣的:(计算机相关试题)