On the passing of parameters in compiled programming languages [closed]

1

What would be most advantageous when calling a function, putting it in the stack from right to left or vice versa? What about cleaning the battery? Does the calling function caller (or calee) have to be responsible for this?

My two cents:

When the calling function is responsible for cleaning the stack, it is possible to create functions with the amount of variable parameters, since it is not necessary to know this amount before the execution time, and only a few more logic is needed. (ex: printf )

Regarding the order in which the arguments are placed in the stack, from left to right allows the first arguments to be used to determine the amount of arguments that the function will receive, however, this is possible in the other order by placing such information in the last arguments, then it is a convention issue, only.

Any add-ons or fixes?

    
asked by anonymous 10.12.2016 / 23:06

1 answer

2
  

What would be most advantageous when calling a function, put it in the stack from right to left or vice versa?

If I understand what you want to know, in your code, it usually makes little difference how you put it. It's interesting to worry about this just because of some optimization for some specific situation, after all you have call convention that put the first parameters directly into the recorder if possible.

We are talking about what architecture? It may vary. What can look good in one may not be the best in another. Even how it compiles can vary. In fact you are speaking of two languages and this will change as well. It may vary based on the API you are using.

Note that there is a difference between you writing your code and what the compiler will do. And what the compiler will do is a decision of it according to the standard convention or else if the code indicates this.

C usually used from right to left. Pascal usually uses left to right. But it's not your code problem unless you need to interoperate or need extreme optimization.

Note that the typical language convention need not necessarily be used in it, nor is it unique to it.

If you are not thinking about optimization, it does not matter how you put the arguments.

  

What about cleaning the battery? Should the caller or caller be responsible for this?

It depends on the convention used, it may be the responsibility of both, each one takes care of a part, which is the case of cdecl , although strictly considered to be the caller who is responsible.

Much of the conventions let the calling function handle the preservation and cleanness of registers, including the pointer to the stack, which tends to make the code more efficient, with stdcall .

  

When the calling function is responsible for cleaning the stack, it is possible to create functions with the amount of variable parameters

It's actually possible to have variable amount of arguments, not parameters .

It's something that I do not know or did not attack or understand the question, the rest seems correct.

    
10.12.2016 / 23:55