C calling conventions and passed arguments

后端 未结 4 1020
-上瘾入骨i
-上瘾入骨i 2021-01-06 05:35

When making a function call in Linux (or OS X for that matter), can the callee modify the values of the arguments on the stack? I was under the assumption that since the ca

4条回答
  •  长发绾君心
    2021-01-06 06:07

    Yes, the callee can modify the arguments on the stack. As far as the callee is concerned, they are the same as local variables. The caller does clean them up but ignores the value.

    If you're talking C or C++ POD, clean up is simply modifying the stack pointer.

    If you're talking about C++ with a destructor, the caller is responsible for invoking the destructor but destructors for generic classes need to be written to cleanup any value.

提交回复
热议问题