-2

Is subroutine executed without stack? Justify your answer with valid arguments

1 Answers1

1

This is more of a homework (or exam) question; particularly the arguments expected will be in the lectures and/or course material.

In practice, many languages do both, but in such a way that it's indistinguishable from always using the stack, because the stack is needed to handle recursion (and, these days, reentrancy), and executing a subroutine without using the stack is treated purely as an optimisation (often, "inlining").

A few very old languages (eg FORTRAN and COBOL) default to not supporting recursion (much less reentrancy), and therefore may or may not use the stack unless a subroutine is specifically marked as "recursive". Whether they use the stack or not for non-recursive subroutines is up to the compiler (and may differ from version to version or even from subroutine to subroutine).

How this maps to the expected answer on your homework (or exam) depends on how these aspects were covered in the lectures and/or course materials; different courses will emphasise different parts, particularly if they deal with a specific programming language (eg. Python vs C/C++/C# vs FORTRAN).

Jiří Baum
  • 6,697
  • 2
  • 17
  • 17