Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It depends on which part of code will clear stack after call. If caller is responsible to clear stack, like in C, to support variable arguments, then called function must return to the original point of call.

If called function is responsible to clear stack, like in Pascal or Forth, then yep, multiple return points are easy to implement and useful to implement something like switch operator. I used it in Pascal, when I was in school. Just pop old return address from stack and push new one.



You are right, but the ancient cdecl function call convention used by C for variable argument lists is really obsolete and it should never be used in any new programming language implementation, even if it has survived until today in various ABI specifications.

Like for the C null-terminated strings, there are many alternative ways to implement variable argument lists and all of them have already been used many years before the first C compilers, e.g. passing a hidden parameter count or implementing transparently for the programmer any printf-like functions as vprintf-like functions.

With the alternative implementations, the stack should always be freed in the invoked function, which also enables various other important features, e.g. tail-call optimization.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: