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
- How do I create a function in C++ that takes in a file name on input and generates a one dimensional integer vector with 10 elements, and gives back the frequency of each element such as x(0) stores how many times 0 occurs in the file.arrow_forwardWrite a C function that is given a pointer to memory, the number of bytes of memory the pointer points at, and two pointers to uint32_t. Your job is to treat the pointer as if it were a pointer to an array of uint32_t, find the min and max values of the array, and write the results to the locations pointed at by the uint32_t pointers. The number of bytes will be a positive multiple of 4. Do not worry about endianess in this problem. Note the tester has command line options -Wall -Wextra -Werror -fsanitize=address to help you catch errors.arrow_forwardWrite a code Using Pointers that can print a table of values for coordinatepoints (x,y) for a given expressiona. Your code should be able to calculate the function values of typey=mx+cb. Ask the user to give input of m and c. Use pointersc. Ask the user to input how many data points of the function he wants togenerate. Use pointersd. Then dynamically allocate memory for those data pointse. Take input for the x coordinates and store them in the allocateddynamic memory using pointers.f. Calculate the corresponding y values and store them in anotherdynamically allocated memory array.g. Print the data points (x and y) in a tabular form. Use pointers.arrow_forward
- Define a C function that takes two char arrays ca1, ca2, and the size of the arrays s1, s2 as the parameters. The program should compare both the arrays and return 1 if both the arrays are equal. Otherwise, return 0. Two char arrays will be equal if all the elements of both arrays are the same.arrow_forwardFor this assignment, you need only write a single-file C program. Your program will:Define a C structure ( sample struct )suitable to hold the defining characteristics of a:Sample (int list_len, float * value_list) - call this format a Sample data record.Write a separate function to :Read a file of delimited Sample data records into an array of pointers to your sample structs. Note: you may use a statically sized array of size 1024, however, each element of the array must be a pointer to a sample struct (as defined above). Initially each element of the array must be set to NULL (to indicated that it is not used), and then later to a dynamically allocated sample struct if it is to be used. Note: after dynamically allocating memory for a sample struct, you have enough memory for each/every component of the structure. However, for each component of that structure that is a pointer, you will eventually need to allocated memory for the “thing” that it points to as well (think array via…arrow_forwardWrite a C language function named count that takes a void pointer and int parameter, representing a memory buffer, and a uint8_t parameter representing a byte, and returns an int result. The returned result should be the number of occurrences of the byte in the bufer. For example if the buffer p pointed to the bytes 01 12 01 23, then count(p, 4, 0x01) should return 2.arrow_forward
- Muscat College wants to maintain the students' record using a C++ Program. They want to add a module of searching in this program so as to search any particular students' information quickly by using Binary Search Technique. The database has Student_ID (int), Name, Grade (A/B/C), and Passing_Year(int) fields in each students' information. Write a C++ program to search a student information using Student_ID. The database is in order. If the searched product is found, then display product information otherwise display “Product not find “. 1) Creating a structure for a Students' record. 2)Accepting inputs (entering students' details) through keyboard at runtime for maximum 20 students. 3) Search (using Binary Search) a particular record based on the field studen_ID4) Show an error if the record is not found5) Show the position of the record found.arrow_forwardWrite a c++ program that determines whether or not a string of alphanumeric characters is a palindrome. Ignore any whitespace characters or punctuation when processing the string. You will be required to demonstrate pointer math and dereferencing. You will be required to separate your interface from your implementation; you must have a header file (.h) for your interface, and a source file (.cpp) for your implementation. Be sure to perform data validation on your input to prevent buffer overflows. Your code should present the user with prompts similar to the following: (image included) Here are some example palindromes you can test with: Mr. Owl ate my metal wormDo geese see God?Was it a car or a cat I saw?Murder for a jar of red rumA nut for a jar of tunaGo hang a salami, I'm a lasagna hog!arrow_forwardWrite a C++ program that asks your if he wants to store student’s data such as name, id (20i-xxxx) andaddress. Your program should be able to store data for any number of student but, efficiently utilizingthe memory.Your program must have the following function.1) TakingInput: Takes input from user regarding student name, id and address.2) StoringData: Data from TakingInput is then passed to this function where it(data) is stored in adata structure.arrow_forward
- Computer Science Use Lex to produce a lexical analyzer. You can use the regular definitions and actions in the page 143 of our text book. You have to include all tests, make files, etc.Submit your solution for q1 and q2; the codes for programming task include test cases and make files. Zip all these together. Using C programming language.arrow_forward#Solve it with C programing Suppose, you are working as a Data Entry Operator in a company. You have created a dataset that contains the names of N employees. Then your supervisor wants you to look for a particular employee by name. (Consider, every name in the data set is unique).Now your task is to write a program which will help you to find out the name which your supervisor is looking for.If found then print a message "Matched" otherwise print "Not Matched". (N.B: Without quotation) The first line of input will take an integer (N) which indicates the number of names in the dataset. Then the second line will take N space-separated strings. The third line of input will take another string as search value. Sample input:5rabbe sharif shazzad polash tutulsharif Sample output:Matched Sample input:4jahid nishat rasel shakibmunna Sample output:Not Matchedarrow_forwardComputer Science code in c++ please .Do NOT use ANY string/character manipulation or arithmetic functions to implement your solution. You may assume that the input to this encryption function is always exactly 16 bits long. Test that input 0xADE1 yields ciphertext (188, 153). You may hard-code these values for testing.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr