Please forgive me if I am asking a silly question but I am trying to understand what the following code is doing as I am trying to convert it to delphi and cant replicate the result.
in the above code tmp has a value of 56257. How does that value come about? My understanding is that tmp should have a value that matches the 37th entry in the array, in this case 13 (0d).
You have an array of bytes (char) but you are trying to access it like an array of u16 (short int). These probably aren't the same size so your pointer arithmetic won't be the same.
Putting aside the disregard for pointer aliasing and the non-guaranteed size of the short, note that 56257 is 0xdbc1, that is, your pointer is pointing at the byte number 74 (and you machine appears to be little-endian)
Since the type of 'tester' is u16*, it is treated by operator+ as an iterator for an array of u16's. By definition, adding a number n to the pointer to the i'th element of an array results in a pointer to the i+n'th element of the same array. The size of the short in your case is indeed 2 bytes, so the (0+37)'th element of the imaginary array of u16's begins at byte 74.
Thank you all very much, I now understand whats going on and how the values are being calculated.
This code is very old and untouched in a long time...long before I started working here and the bit you are seeing is only an extract that has been simplified to show my problem and is perhaps obsolete now, but until I can understand it I cant really say for sure.