2013-03-01 48 views
0

我正在準備一個編譯器檢查,我發現在過去的論文以下兩個問題,我不知道該怎麼回答:編譯考試說明

1. Array bounds checking requires code to check each array subscript to ensure it 
falls within the array's declared range. How could induction variable analysis be 
used to avoid repeated bounds checks in "for" loops. 

2. Give a short example in Java in which one array address calculation is loop- 
invariant and another array address is an induction variable. 

我知道什麼是不變的,並歸納變量手段,關於解釋這兩個解決方案,我並不知道我期望什麼。

如果有人幫我解釋,我將不勝感激。

謝謝!

回答

0

第一個很簡單 - 因爲每次迭代的歸納變量增加固定的數量,所以可以預先計算任何用作數組下標的歸納變量的最大值,並檢查它是否不超過數組邊界。在執行循環之前,你會這樣做一次,而不是在每次迭代時檢查下標。對於第二種,有很多循環不變和感應變量循環的示例(包括Java在內的各種語言) - 只是Google針對這些術語的示例。