Why are parentheses and periods after an array name instead of brackets?

When accessing an array element, square brackets are used like this:

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

However, while reading the code of others, 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].); 
  • What does it mean to have parentheses after the array name, as in PBox(someNumber) ? Is this another way to access an array element?
  • What is he doing "." before SBox1 and after SBox2 means? Both SBox1 and SBox2 are arrays. The code compiles without errors, but I don’t know what these points are for.
+7
source share
1 answer

Yes, now I see what you are doing.

In fact, (. And .) Are simply alternative ways (but very unusual!) Of writing [ and ] in Delphi.

If PBox is an array, then PBox[a] (or, equivalently, PBox(.a.) ) PBox(.a.) require a be an integer, right? And if SBox1[x] and SBox2[Y] are integers, then their bitwise or . (A bitwise or is an operation that takes two integers and returns a new integer.) Therefore, PBox(.SBox1[X] or SBox2[Y].) Is the (SBox1[X] or SBox2[Y]) th element in PBox array, i.e. an integer. Therefore, it makes sense to calculate the bitwise or between Result and this integer, which is done:

 Result := Result or PBox(.SBox1[X] or SBox2[Y].); 
+16
source

All Articles