Suppose we are compiling for a machine with 1-byte characters, 2-byte shorts, 4-
ID: 3813211 • Letter: S
Question
Suppose we are compiling for a machine with 1-byte characters, 2-byte shorts, 4-byte integers, and 8-byte reals, and with alignment rules that require the address of every primitive data element to be an even multiple of the element's size. Suppose further that the compiler is not permitted to reorder fields. How much space will be consumed by the following array? Explain.
"Suppose further that the compiler is not permitted to reorder fields." What does this sentence mean?
How to solve this question?
Explanation / Answer
It requires 240 bytes.
Each element of the array,
s offset = 0
c offset = 2
t offset = 4
d offset = 6
r offset = 8
i offset = 16
i has added with 4 more bytes then 16+4=20 but 20 is not an multiple of 8
We therefore pad each element out to 24 bytes so that field r will be aligned in each array elemen
Array has 20 elements [0..9]
So the total length 24*10=240 bytes.
Suppose further that the compiler is not permitted to reorder fields indicates that volatile memory has not much spacei.e, Available RAM is consumed by the program for compilation and it cannot further reorder the variables. Barriers prevent a compiler from reordering instructions during compile time deals only with the memory when the program got loaded in the primary memory.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.