Question: Q)Consider the following structure declaration containing a structure within a structure, and answer the following questions. struct person{ struct size{ int height; int weight; }s;

Q)Consider the following structure declaration containing a structure within a structure, and answer the following questions.

struct person{

struct size{

int height;

int weight;

}s;

int *hp;

int games[2];

}person1, person2;

How many total bytes does the structure require?

height

weight

hp

games[0]

games[1]

What are the offsets in bytes of the following fields?

s.height: ______________

hp:_______________

games[1]:______________

The compiler generates the following assembly code for the body of str_init (shown below).

movq 16(%rbp), %rax //Get p1 into register %rax

movl 4(%rax), %edx //Get p1->s.weight store in register %edx

movq 16(%rbp), %rax //Get p1 into register %rax

movl %edx, (%rax) //Store in p1->s.height

movq 16(%rbp), %rax //Get p1 into register %rax

leaq 4(%rax), %rdx //Compute address of p1->s.weight in register %rdx

movq 16(%rbp), %rax //Get p1 into register %rax

movq %rdx, 8(%rax) //Store in p1->hp

On the basis of this information, fill in the missing expressions in the code for str_init.

void str_init(person *p1)

{

p1->s.height = _____________;

p1->hp = _________________;

}

How would you call str_init with the struct person1 passed to it?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!