GATE / CS ARCHIVE

GATE CSE 2014 SET 2 / QUESTION 34

GATE CSE 2014 Set 2 Q34

Compiler Design · Intermediate Code · Full GATE CSE 2014 Set 2 paper

GATE 2014 Set 2, Q34 2 marks · MCQ
Report issue

Intermediate Code

Question 34, GATE 2014: A compiler accesses X[i][j][k] using byte-offset code t0=i*1024; t1=j*32; t2=k*4; t3=t1+t0; t4=t3+t2; t5=X[t4]. Integers are 32 bits, characters 8 bits. Which declaration matches? A int X[32][32][8]; B int X[4][1024][32]; C char X[4][32][8]; D char X[32][16][2].
Tap to enlarge
Your answer
Answer & solution

Official answer: A

1. Set up the reasoning. For a row-major three-dimensional array with element size e and trailing dimensions d2,d3, the offset is e·(i·d2·d3+j·d3+k). Match its three coefficients to the generated code.

2. Derive the result. The byte strides show 4-byte int elements, 8 elements in the last dimension(32/4), and 32 in the middle dimension(1024/32). The first dimension is not recoverable from strides alone, but among the listed declarations only int X[32][32][8] matches. Thus A.

3. Check the interpretation. The innermost coefficient identifies e=4 bytes; j then gives d3=8 and i gives d2=32. The leading dimension is not encoded in these strides, so select the matching offered declaration without claiming that 32 as its first dimension was derived.

Original paper, page 38 · Answer key