Skip to main content
edited body
Source Link
CPlus
  • 9.2k
  • 2
  • 33
  • 96

This is more a question about compiler design than language design, but in low level languages, when a function is called, the parameters are pushed onto the stack, and when the function returns, the parameters are cleared from the stack.

As I understand this, one way that the stack is cleared is that the calleecaller clears up the stack, where instructions to clear the parameters are inserted after the call instruction at the call site. Another way is that callercallee clears the parameters, where the last instructions of the function body are the instructions to clean up the parameters.

What are the reasons to choose one implementation over the other?

Inspired by this answer.

This is more a question about compiler design than language design, but in low level languages, when a function is called, the parameters are pushed onto the stack, and when the function returns, the parameters are cleared from the stack.

As I understand this, one way that the stack is cleared is that the callee clears up the stack, where instructions to clear the parameters are inserted after the call instruction at the call site. Another way is that caller clears the parameters, where the last instructions of the function body are the instructions to clean up the parameters.

What are the reasons to choose one implementation over the other?

Inspired by this answer.

This is more a question about compiler design than language design, but in low level languages, when a function is called, the parameters are pushed onto the stack, and when the function returns, the parameters are cleared from the stack.

As I understand this, one way that the stack is cleared is that the caller clears up the stack, where instructions to clear the parameters are inserted after the call instruction at the call site. Another way is that callee clears the parameters, where the last instructions of the function body are the instructions to clean up the parameters.

What are the reasons to choose one implementation over the other?

Inspired by this answer.

Became Hot Network Question
Source Link
CPlus
  • 9.2k
  • 2
  • 33
  • 96

What are the advantages and disadvantages of the callee versus caller clearing the stack after a call?

This is more a question about compiler design than language design, but in low level languages, when a function is called, the parameters are pushed onto the stack, and when the function returns, the parameters are cleared from the stack.

As I understand this, one way that the stack is cleared is that the callee clears up the stack, where instructions to clear the parameters are inserted after the call instruction at the call site. Another way is that caller clears the parameters, where the last instructions of the function body are the instructions to clean up the parameters.

What are the reasons to choose one implementation over the other?

Inspired by this answer.