开发者

Why are there parentheses and dots after an array's name instead of brackets?

When accessing an element in an array the square brackets are used like so:

{'X is an int and Numbers is an int array'}
X := Numbers[8];

However, While reading others' code I sometimes find the following syntax:

{'PBox , SBox1 , SBox2 are arrays of int , And X,Y are ints'}
Result := Result or PBox(.SBox1[X] or SBox2[Y].);
  1. What does it mean to have p开发者_高级运维arentheses after the array's name, as in PBox(someNumber)? Is this another way to access an array element?
  2. What does the "." before SBox1 and after SBox2 mean? Both SBox1 and SBox2 are arrays. The code compiles without error but I don't know what those dots are for.


Yes, now I see what you do.

In fact, (. and .) are merely alternative ways (but very uncommon!) of writing [ and ] in Delphi.

If PBox is an array, then PBox[a] (or, equivalently, PBox(.a.)) would require a to be an integer, right? And if SBox1[x] and SBox2[Y] are integers, so is the bitwise or of them. (Bitwise or is an operation that takes two integers and returns a new integer.) Hence, PBox(.SBox1[X] or SBox2[Y].) is the (SBox1[X] or SBox2[Y])th element in the array PBox, that is, an integer. So it makes sense to compute the bitwise or between Result and this integer, which is what is done:

Result := Result or PBox(.SBox1[X] or SBox2[Y].);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜