answersLogoWhite

0


Best Answer

Calling an in-line function, which is not actually a function-call.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which function call Does not consume stack space?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the maximum depth of recursive calls a function may make?

Recursive function call depend your primary memory space because the recursive call store in stack and stack based on memory.


How are arguments passed to a function?

Arguments are passed to functions via the thread's function call stack. Every thread has its own call stack, which is a small region of contiguous, fixed-size memory that extends downwards into lower addresses. The stack is allocated when the thread is instantiated and deallocated when the thread terminates thus there is minimal cost in using the stack. Data is pushed and popped from the stack while a stack pointer keeps track of the top of the stack (the lowest unused address).


How are functions invoked in cpp?

If the function is inline expanded then it is not invoked at all -- there is no function call. However, if the function is not or cannot be inline expanded, a procedure call is invoked. This pushes the calling function's local values onto the stack, followed by the return address, followed by the callee's argument values in reverse order. Control is then passed to the address of the function. The function then pops the arguments off the stack and assigns them to its local parameters (parameters that are passed by value will automatically invoke the copy constructors of those parameters). The function then executes. When a return statement is encountered, the return address is popped from the stack, the return value (if any) is pushed onto the stack, and control is passed to the return address. When a function returns, the return value (if any) and the local values are popped from the stack, and execution continues from where it left off.


Explain the allocation of memory cells when a function is called?

When you call a function, the stack pointer is adjusted to cater for the function's arguments (if any), the caller's return address (mandatory), the function's local variables (if any) and the function's exception handlers (if any).


What is the role of stack in function call?

It depends on the language. Some use one stack for everything within a program while others use multiple stacks for different purposes (return addresses, local variables, function arguments, exception handling and so on). For the purpose of this answer we shall assume a single stack. The basic purpose of the stack is to allow functions to be invoked from multiple call sites and for those functions to be able to return control to the site that invoked them. If a function only has one call site then there is no need to make a function call at all; the code can simply be inline expanded by the compiler. The same applies to trivial functions that do very little work, such as a function that computes a simple value to be returned to the caller. Thus the programmer gains the benefit of having a function call that makes his code self-documenting and therefore easier to read, without the inconvenience of making an expensive function call. However, when a function has multiple call sites and the function is too large to be inline expanded (because large code typically reduces performance, negating the benefit of inline expansion), the function needs to know from where it was called so that it can return control to the callee when it has completed its task. This is achieved by the call site pushing a return address onto the call stack. When the called function is finished, the return address can be popped from the stack and control returned to the caller. This process is generally known as winding and unwinding the stack, because it allows functions to call functions (to call functions) without losing track of where the calls came from. This also allows functions to recursively call themselves. The stack is also used to store local variables. That is, variables that are scoped to a code block. When the block comes into scope, the variable is pushed onto the stack and when the block falls from scope, the variable is popped from the stack. Thus local variables are only visible from within the scope in which they are declared. Code blocks may also be nested, such that variables within the scope of the outer block are visible to code within the inner block, but variables within the scope of the inner block are not visible to code within the outer block. If an inner variable has the same name as an outer variable, the outer variable is hidden from the inner scope. Such trickery is best avoided as it makes code harder to read. However, a function is itself a code block, thus a function's local variables will make use of the stack. Most functions also accept arguments (or parameters). In order to pass these arguments from the caller to the callee, the arguments are pushed onto the stack. The stack is typically divided up into frames, such that each frame is only of relevance to a particular function. The frame at the top of the stack relates to the current function, and the one below relates to the function that called the current function. The current function's local variables are placed at the top of its frame, followed by the return address of the call site, followed by the arguments that were passed to the function from the call site. If a function returns a value, the caller can store that value by assigning the function to a suitable variable. A function's return value is typically pushed onto the stack immediately after popping the function's stack frame, but if the function is not assigned to a variable, that value is lost forever. This is desirable when a return value is provided by a function but is not actually required by the caller. The value still exists at the top of the stack, just beyond the stack pointer, but short of inline assembly there's no way to retrieve it before the next function call, which will overwrite it with its stack frame. Other information that may be contained in a function's frame include its exception handlers, if any. When an exception occurs and no exception handler is available, the current function immediately terminates, unwinding the stack. The stack will continue to unwind, prematurely terminating each function in turn, until a frame containing a suitable handler is found. It is vital that exception handlers make use of RAII (resource acquisition is initialisation) to ensure any resources acquired between the exception handler and the code that caused the exception are released back to the system in an orderly manner. Raw pointers to allocated memory must be avoided at all costs; use resource handles or smart pointers instead. If the stack completely unwinds then no handler was found and the program terminates with an unhandled exception error. Ugh! These can be extremely difficult to trace, therefore it is vital that you place a catch-all handler in the program's main function to capture as much information about unhandled exceptions as possible, and handle it as gracefully as possible. You can then use this information to (hopefully) provide a suitable handler within the appropriate function.

Related questions

What is the maximum depth of recursive calls a function may make?

Recursive function call depend your primary memory space because the recursive call store in stack and stack based on memory.


Basic concept and application of stack?

A stack is a last in first out (LIFO) data structure. Stacks are typically used in backtracking algorithms where values are popped off the stack in the reverse order they were pushed onto the stack. Procedural programming languages make use of a call stack so that functions can easily return control to their callers -- which is vital when a function may have more than one call site. The calling function pushes the return address onto the call stack and then passes control to the callee function. When the callee has finished its task, the return address is popped off the stack and control returned to that address. In this way, functions can call other functions (including themselves) without losing track of where those calls came from. The call stack is also used to store a function's local variables as well as any arguments that were passed to the function by its caller. The function's exception handlers can also be placed on the stack. When an unhandled exception occurs, the call stack unwinds until a stack frame with a suitable exception handler is located. If the call stack unwinds all the way to the program's entry point (the main function) and there is still no handler, the program terminates with an unhandled exception error.


In C plus plus How does a function pass control back to the calling function?

The calling code pushes the return address onto the call stack. When the function returns, it pops the return address off the call stack and returns control to that address. The call stack (or simply the stack), is also used to pass parameters to functions and to receive return values from functions, as well as for local storage, evaluation, and the this pointer when calling class member functions. Functions that call other functions, or that recursively call themselves, will increase consumption of the call stack accordingly. This is known as winding, because the return addresses will remain on the stack until the function is ready to return (even if the function calls itself or another function), thus allowing functions to automatically unwind. In other words, it's a bit like leaving a trail of breadcrumbs (as per the Hansel & Gretel fairytale) allowing functions to retrace their steps back to the original call site and, ultimately, back to the main function.


How are arguments passed to a function?

Arguments are passed to functions via the thread's function call stack. Every thread has its own call stack, which is a small region of contiguous, fixed-size memory that extends downwards into lower addresses. The stack is allocated when the thread is instantiated and deallocated when the thread terminates thus there is minimal cost in using the stack. Data is pushed and popped from the stack while a stack pointer keeps track of the top of the stack (the lowest unused address).


Can anybody explain stack level functioning of recursion in c language exclusively?

Yes, any body can explain stack level functioning of recursion in C language exclusively. ;-) Whenever we invoke a function, the return address is pushed onto the call stack. That return address remains on the call stack until the function returns at which point the address is popped from the stack and control passed to that address. In this way, functions can always find their way back to their callers, even if those functions invoke other functions, including themselves (recursive functions). As well as the return address, the formal arguments of the function and the local variables of the function are also pushed onto the stack. Formal arguments are initialised by the actual arguments passed by the caller, assigning the values of the actual arguments to the formal arguments. If the formal argument is a pointer variable or reference, the address of the actual argument is passed instead. In addition, the call stack is used by the exception handling mechanism. When an exception is thrown by a function, the call stack "unwinds" (popping each function's stack frame) until a suitable handler is found.


What does 'stack overflow at line 1776' mean?

This probably means that the stack ran out of memory when the program reached line 1776. This is in many cases caused by a function that calls itself too many times, since each function call takes up memory on the stack and that memory is not returned until the function exits.


How can you call a function written in FORTRAN from a C program?

Is the FORTRAN function part of a library. If it is it will be no different from call a c function in a library. There could be an issue the order that the functions attribures are pusshed onto the stack like there is with pascal.


Why is this following C program returning a Segmentation Fault 11?

Without seeing the code it is impossible to say, however the error indicates the code has caused a stack overflow and that typically indicates a recursive function that either has no end-point or has an end-point that exceeds the limits of the call stack. Either that or you have attempted to allocate memory upon the stack when there is insufficient unused memory available on the stack. The call stack is a fixed length memory allocation used to store thread-local variables, return addresses and formal arguments. Every thread of execution has its own call stack, but once a stack is exhausted or there is insufficient space to meet an allocation at runtime, the thread cannot proceed and thus terminates with a segmentation fault.


How are functions invoked in cpp?

If the function is inline expanded then it is not invoked at all -- there is no function call. However, if the function is not or cannot be inline expanded, a procedure call is invoked. This pushes the calling function's local values onto the stack, followed by the return address, followed by the callee's argument values in reverse order. Control is then passed to the address of the function. The function then pops the arguments off the stack and assigns them to its local parameters (parameters that are passed by value will automatically invoke the copy constructors of those parameters). The function then executes. When a return statement is encountered, the return address is popped from the stack, the return value (if any) is pushed onto the stack, and control is passed to the return address. When a function returns, the return value (if any) and the local values are popped from the stack, and execution continues from where it left off.


Explain the allocation of memory cells when a function is called?

When you call a function, the stack pointer is adjusted to cater for the function's arguments (if any), the caller's return address (mandatory), the function's local variables (if any) and the function's exception handlers (if any).


What is the role of stack in function call?

It depends on the language. Some use one stack for everything within a program while others use multiple stacks for different purposes (return addresses, local variables, function arguments, exception handling and so on). For the purpose of this answer we shall assume a single stack. The basic purpose of the stack is to allow functions to be invoked from multiple call sites and for those functions to be able to return control to the site that invoked them. If a function only has one call site then there is no need to make a function call at all; the code can simply be inline expanded by the compiler. The same applies to trivial functions that do very little work, such as a function that computes a simple value to be returned to the caller. Thus the programmer gains the benefit of having a function call that makes his code self-documenting and therefore easier to read, without the inconvenience of making an expensive function call. However, when a function has multiple call sites and the function is too large to be inline expanded (because large code typically reduces performance, negating the benefit of inline expansion), the function needs to know from where it was called so that it can return control to the callee when it has completed its task. This is achieved by the call site pushing a return address onto the call stack. When the called function is finished, the return address can be popped from the stack and control returned to the caller. This process is generally known as winding and unwinding the stack, because it allows functions to call functions (to call functions) without losing track of where the calls came from. This also allows functions to recursively call themselves. The stack is also used to store local variables. That is, variables that are scoped to a code block. When the block comes into scope, the variable is pushed onto the stack and when the block falls from scope, the variable is popped from the stack. Thus local variables are only visible from within the scope in which they are declared. Code blocks may also be nested, such that variables within the scope of the outer block are visible to code within the inner block, but variables within the scope of the inner block are not visible to code within the outer block. If an inner variable has the same name as an outer variable, the outer variable is hidden from the inner scope. Such trickery is best avoided as it makes code harder to read. However, a function is itself a code block, thus a function's local variables will make use of the stack. Most functions also accept arguments (or parameters). In order to pass these arguments from the caller to the callee, the arguments are pushed onto the stack. The stack is typically divided up into frames, such that each frame is only of relevance to a particular function. The frame at the top of the stack relates to the current function, and the one below relates to the function that called the current function. The current function's local variables are placed at the top of its frame, followed by the return address of the call site, followed by the arguments that were passed to the function from the call site. If a function returns a value, the caller can store that value by assigning the function to a suitable variable. A function's return value is typically pushed onto the stack immediately after popping the function's stack frame, but if the function is not assigned to a variable, that value is lost forever. This is desirable when a return value is provided by a function but is not actually required by the caller. The value still exists at the top of the stack, just beyond the stack pointer, but short of inline assembly there's no way to retrieve it before the next function call, which will overwrite it with its stack frame. Other information that may be contained in a function's frame include its exception handlers, if any. When an exception occurs and no exception handler is available, the current function immediately terminates, unwinding the stack. The stack will continue to unwind, prematurely terminating each function in turn, until a frame containing a suitable handler is found. It is vital that exception handlers make use of RAII (resource acquisition is initialisation) to ensure any resources acquired between the exception handler and the code that caused the exception are released back to the system in an orderly manner. Raw pointers to allocated memory must be avoided at all costs; use resource handles or smart pointers instead. If the stack completely unwinds then no handler was found and the program terminates with an unhandled exception error. Ugh! These can be extremely difficult to trace, therefore it is vital that you place a catch-all handler in the program's main function to capture as much information about unhandled exceptions as possible, and handle it as gracefully as possible. You can then use this information to (hopefully) provide a suitable handler within the appropriate function.


How the stack memory is getting affected when performing the recursive operation in C?

Each time you call a function, a new stack page is created for that function. The same happens when a function recursively calls itself. Small functions or functions that are seldom invoked can be inline expanded by the language compiler or linker to reduce stack usage. However recursive functions are generally only expanded to a specified depth of recursion; all remaining recursions are handled by the usual function call mechanism. The stack page of a function is used to store the function's return address, formal arguments and local variables, as well as to provide exception handling information where required. Invoking a function is more costly than executing the same code inline due to the need to instantiate a stack page and copy values to it. However, functions make our code much easier to read and maintain while inline expansion helps to eliminate the cost of calling a function.