Practice Problem 3.43 (solution page 344)
Suppose you are given the job of checking that a C compiler generates the proper code for structure and union access. You write the following structure declaration:
typedef uniun {
struct {
long u;
short v;
char w;
} t1;
struct {
int a [2];
char *p;
} t2;
} u_type;
You write a scries of functions or the form
void get (u_type *up, type *dest) {
*dest = expr;
}
with different access expressions expr and with destination data type type set according to type associated with expr. You then examine tire code generated when compiling the functions to see if they match your expectations.
Suppose in these functions that up and dest are loaded into registers %rdi and %rsi, respectively. Fill in the following table with data type type and sequences of one to three instructions to compute the expression and store the result at dest.
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Additional Engineering Textbook Solutions
Starting Out With Visual Basic (7th Edition)
Starting Out with Java: Early Objects (6th Edition)
Starting Out with Python (3rd Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Digital Fundamentals (11th Edition)
Java How To Program (Early Objects)
- C++ Programming. Topic: Working with pointers and dynamic memory. Indicators. Working with dynamic memory. Dynamic arrays and their use as function parameters. Task : Describe a void function named Swap(x,y) that swaps the values stored in the variables x and (x is a real type parameter and is both input and output). Using this function , for the given variables of real type a, b, c, d, one should sequentially replace the values of the pairs (a, b), (c, d) and (b, c) and let a, b, c, d be new values .arrow_forwardConsider the following function definition.void mystery(int* x){// function body } Inside the definition of mystery, the C++ language provides a way to distinguish if x points to a lone int value or to an int allocated as part of a larger array.A. True B. Falsearrow_forward[C PROGRAMMING] Write a program in C: 1. The circle has two data members, a Point representing the center of the circle and a float value representing the radius as shown below. typedef struct{ Point center; float radius; }Circle; Implement the following functions: a. float diameter(Circle circ); //computes the diameter of a circle. b. float area(Circle circ); //computes for area of a circle c. float circumference(Circle circ);//computes for the circumference of a circlearrow_forward
- C programing (condition using pointers) Q1) Write a function called letter grade that has a type int input parameter called points andreturns through an output parameters gradepLetter and gradepNumber. The appropriate lettergrade matching is given in the table below. Return through a second output parameter(just_missedp) an indication of whether the student just missed the next higher grade (true for89, 79, 64 and so on).Prototype: void letter_grade(int points, char *gradepLetter, char*gradepNumber, char *just_missedp);arrow_forwardC++ (Please answer the ques with showing the code) Question : Operator Overloading a) Implement two unary operator overload functions (-,+,!). b) Implement four arithmetic operator overload functions (+,-,*,/). c) Implement six relational operator overload functions (==,!=,>,>=,<,<=). d) Implement the insertion operator overload function (<<). e) Implement the extraction operator overload function (>>). f) Implement the subscript operator overload function ([]). Make sure that each function is optimally overloaded for its purpose. (pick between member, non-member, friend as appropriate) Notes Add Rational Numbers Given a/b + c/d: Step 1: Find the LCM of b and d. Step 2: Create a new Rational Number: ((a*(LCM/b) + (c*(LCM/d)) / LCM. Step 3: Reduce the new Rational Number from step 2. Step 4: Return the new Rational Number. Subtract Rational Numbers Given a/b - c/d: Step 1: Find the LCM of b and d. Step 2: Create a new Rational Number: ((a*(LCM/b) - (c*(LCM/d))…arrow_forwardDescribe how memory allocation is done to objects and also develop a C++ programfor employee class with following attributes such as Employee ID, Employee Name,Designation and Salary. Program should sort and display the list of employees inascending order of their salaries using object as a function argument. (Note:Employee ID must not be inputted by the user i.e., auto incremented.)arrow_forward
- Instructions: In this exercise, we are going to review a bunch of Haskell structures. (1) Use case expressions to define function multList2 that receives a list of numbers and returns a list in which every element of the input list is multiplied by 2. Do not forget to annotate the types.arrow_forward3- Write a function pow (double base, int exp) to calculate integral powers of floating-point numbers. Arguments: The base of type double and the exponent of type int. Returns: The power baseexp of type double. For example, calling pow( 2.5, 3) returns the value 2.53 = 2.5 * 2.5 * c++ program 2.5 = 15.625 This definition of the function pow( ) means overloading the standard function pow ( ), which is called with two double values. Test your function by reading one value each for the base and the exponent from the keyboard. Compare the result of your function with the result of the standard function. Hint: The power x° is defined as 1.0 for a given number x. • The power x" is defined as (1/x)-" for a negative exponent n. The power 0" where n > 0 will always yield 0.0 . The power 0" is not defined for n < 0. In this case, your function should return the value 0. Don't forget the negative exponentarrow_forward7- In how many ways can we pass arguments to a C++ function? a) One. b) Two. I need a sure answer 100% with explanation only solve number 10 c) Three. d) Unlimited 8- To access the value that the pointer is pointing to, we use 9- Is it possible to alter the address that the reference points to? (Yes or No) 10- We can write as many constructors in a C++ class as we want. (True or False)arrow_forward
- Task - Encode a string (C Language) Modify Project #2, Task #1 (given below) so that input characters are command line arguments. Requirements Name your program project5_encode.c. Input characters are command line arguments. There can be any number of command line arguments. Assume the total number of input characters is no more than 1000. Character handling library functions in ctype.h are allowed. The program should include the following function: void encode(char *input, char *output); The function expects input to point to a string containing the string to be encoded, output to point to a string containing the result. The program should also check if the number of arguments on the command line is greater than or equal to 2. If the number of arguments is 1, the program should display the message "Invalid input!". Examples (your program must follow this format precisely) Example #1 $ ./a.out 7 + 8Output: 3_4 Example #2 $ ./a.out usf.eduOutput: ayl_kja Example #3 $…arrow_forwardQ.1) Mark the following statements as true or false and correct the second part if false: 1. The statement: int A [3][3]={{0,3};{0,2}.(0,1}}; initialized the matrix A to: 0 3:0 2:0 1. 2. User-defined functions in C++ classified into two categories: standard and pre-defined functions. 3. When used the predefine function cos(x) we must include the header 4. The following loop: for (index = 0; index < 20; index=index+1) sale[index] = index%2; Initialize the even components of sale to 0 and odd components to 1 5. The syntax of void function with parameters is : datatype functionName ( ) { Statements 6. The statement double List [15]; Declares a one-dimensional array List, the components of the The components are List[0], List[1],.., List[14]. 7. To initializes the 1* column of the matrix[4][5] to 0, we can use the following segment of program: for (row 0; row <= 4; row++) for (col = 0; col <= 5; col++) matrix[row][col] =0; 8. Struct is a collection of a fixed number of components in which…arrow_forwardC++ Problem 1: (Monte Carlo Experiments) The Monte Carlo method is used in modeling a wide-range of physical systems at the forefront of scientific research today. Let’s consider the problem of estimating the area of the region x 2 + 2y 2 ≤ 1 by utilizing the Monte Carlo method. This region is enclosed by a blue ellipse, which is inscribed in a 2 × 2 red square (shown in the figure below). The experiment simply consists of throwing darts on this figure completely at random (meaning that every point in the red square has an equal chance of being hit by the dart). You keep throwing darts at random. All of the darts fall within the square, but not all of them fall within the ellipse. If you throw darts completely at random, this experiment estimates the ratio of the area of the ellipse to the area of the square, by counting the number of darts within each area. Program this Monte Carlo method to compute the area of the blue ellipse using different numbers of darts. For each experiment,…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education