Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 489 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why are there so many different calling conventions?

#1
Historically, why does it seem like just about everyone and their kid brother defined their own calling conventions? You've got C, C++, Windows, Pascal, Fortran, Fastcall and probably a zillion others I didn't think to mention. Shouldn't one convention be the most efficient for the vast majority of use cases? Is there ever any good reason to prefer one over the other?
Reply

#2
Because historically everyone and their kid brother did define their own calling conventions. They were all created for different purposes and thus driven by different performance needs. For instance, C++ favours optimisations for passing the `this` parameter.
Reply

#3
- Some of them are more efficient regarding performance and others more efficient in code size.
- Some features (variable arguments count) are only supported with some conventions.

More Information:

[To see links please register here]

Reply

#4
Part of the reason is the underlying architecture of the microprocessor (or processor). Most languages start on a specific CPU, and get entangled a bit with that architecture. For example, the old Univac 1100 series computer didn't even have a call stack!

Another part of the reason is that is is not possible to foresee the best solution until you've tried several ways of doing things.
Reply

#5
The calling conventions you mention were designed over the course of decades for different languages and different hardware. They all had different goals. cdecl supported variable arguments for printf. stdcall resulted in smaller code gen, but no variable arguments. Fastcall could greatly speed up the performance of simple functions with only one or two arguments on older machines (but is rarely a speed up today.)

Note than when x64 was introduced, on Windows at least, it was designed to have a single calling convention.

Raymond Chen wrote a great series on the history of calling conventions, you can start [here][1].


[1]:

[To see links please register here]

Reply

#6
They're created for different purposes, and with different optimization systems.

For instance, to reduce "Stack Overflow," (no pun intended) some people thought of various ideas to call function to make stack overflows impossible.

Another instance is the Lambda Calculus. Not to be too vague, but in Lambda, functions may only pass one argument and return one value, and thus also need their own calling conventions.
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through