Concept explainers
For this exercise, we will examine the code generated by GCC for functions that have structures as arguments and return values, and from this see how these language features are typically implemented.
The following C code has a function process having structures as argument and return values, and a function values, and a function eval that tails process.
Gcc generates the following code for these two functions:
A. We can see on line 2 of function eval that it allocates 104 bytes on the stack. Diagram the stack frame for oval, showing the:Nal= that it stores on the stack prior to calling process. B. What value does eval pass in its call to process?
C. How does the code for process access the elements of structure arguments?
D. How does the code for pro cess set the fields of result structure r?
E. Complete your diagram of the stack frame for eval, showing how eval accesses the elements of structure r following the return from process.
F. What general principles can you discern about how structure values are passed as function arguments and how they are returned as function results?
Learn your wayIncludes step-by-step video
Chapter 3 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Additional Engineering Textbook Solutions
Starting Out With Visual Basic (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Absolute Java (6th Edition)
Starting Out with C++: Early Objects
- a.)Write a C++ program that consists of a function declaration, a function definition and a main. The function declaration is as follows: void endTime (int ch, int cm, char cap, int dh, int dm, int eh, int em, char eap)// given any current hour, minutes and 'A' or 'P' for am/pm in parameters ch, cm and cap respectively,// and also given the duration (hours and minutes) of an activity in parameters dh and dm,// the function stores the end time in parameters eh, em and eap. Where eh will hold the hour of the end time, em holds the minute and eap holds eithe 'A' or 'P' for the end time.// All values are using a 12 hour clock// Function assumes all activities end in the same day Also include a main program that feeds the following arguments to the functions:11, 25, 'A', 3, 45, hour, minute, ampm causing the function to calculate the end time as 3 10 PUsing the calculated results, the main then outputs:If the current time is 11:25AM and we have 3 hours and 45 minutes to go, we have to sit…arrow_forwardIllustrate with an example program as to what happens when the compiler encounters a function template in C++? Explain what happens when the template is invoked and when it is not invoked. Add comments to your program wherever necessary. PROVIDE CODEarrow_forwardIs that correct?Pointers or references are required for dynamically bound virtual functions.arrow_forward
- This question has been answered in C, but without user-defined functions; an answer with user defined functions would be helpful.arrow_forwardThis is to be done in ML coding language. Please provide the actual code, and try to keep the code as simple as possible. Define a function which computes the product of all integers betweenm and n (with n >= m) inclusive. Use this function to define the function Cn,k (thenumber of combinations of n elements taken k by k), which is defined by Cn,k = n!/(k!*(n-k)!) Test your code with sample input and report result.arrow_forwardQuestion 2. Consider the following skeletal C program. void fun1(void) {int a, b, c;// call another function} void fun2(void) {int d, e, f;// call another function} void fun3(void) {int c, d, e;// call another function} void main () {int a, f, e;// call another function} Given the following calling sequences and assuming that dynamic scoping is used, whatvariables are visible during execution of the last function called? Include with each visiblevariable the name of the function in which it was defined. a. main calls fun1; fun1 calls fun3.b. main calls fun3; fun3 calls fun1.c. main calls fun1; fun1 calls fun3; fun3 calls fun2.d. main calls fun3; fun3 calls fun2; fun2 calls fun1arrow_forward
- In the context of function calls, please explain the difference between reference semantics and value semantics, as well as the repercussions of this distinction. When is it OK to choose one option over the other? What are the advantages of both options?arrow_forwardExplain, with the use of an illustration, how the background process of invoking inline functions varies from that of calling a normal function.arrow_forwardConsider the following defintion: data Term = Var String | Application Term Term | Lambda String Term Construct a Haskell function: alphaRename :: Term -> String -> Term Where it performs an alpha renaming. (alphaRename t x) substitutes x for the formal parameter of t, which must be a lambda expression. You can assume that x is not free in t, i.e., not free in the body of t. Please provide your function code with an example input for the above operation.arrow_forward
- Write an FP(functional programming) function to implement each of the following definitions.a. f(n) = ⟨(0, 0), (1, 1), . . . , (n, n)⟩.b. f ((x1, . . . , xn), (y1, . . . , yn)) = ⟨(x1, y1), . . . , (xn, yn)⟩ and program it in either Java or python to show how it worksarrow_forwardDevelop a function template in C++ that would sort an array of the data types that are provided.arrow_forwardSuppose that the function qux is guaranteed to return an integer between -365 and 350 inclusive. If you wanted to compare the return value of this function against the target value -27 with a structure that would send the flow of control down a different path depending on whether the return value was less than or greater than or equal to the target value then which of the following branching structures would be the best approach? This question is internally recognized as variant 250. Q6) fragment 1 contains the correct code fragment 2 contains the correct code fragment 3 contains the correct code fragment 4 contains the correct code fragment 5 contains the correct code fragment 6 contains the correct code fragment 7 contains the correct code fragment 8 contains the correct code none of the abovearrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr