Question: Problem 2 : Struct and Union Memory Layout Consider the following C declarations. Assume the following data type sizes: char: 1 byte short: 2 bytes
Problem : Struct and Union Memory Layout
Consider the following C declarations. Assume the following data type sizes:
char: byte
short: bytes
int: bytes
double: bytes
Assume the compiler:
Does not reorder fields.
Aligns each data type to its natural alignment size of the data type
Structures are aligned to the largest alignment requirement of their members.Tasks:
Memory Size Calculation
a Calculate the size in bytes of union Info.
b Calculate the size in bytes of struct Record.
Offset Calculation
Determine the offsets in bytes of:
a data.value
b status
Memory Optimization
Reorder the members of struct Record to minimize memory usage. Calculate the new size of struct Record after reordering.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
