Einzelnen Beitrag anzeigen

Der schöne Günther

Registriert seit: 6. Mär 2013
6.176 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: C++ pointer to byte array --> Delphi

  Alt 1. Dez 2013, 21:02
This is sorcery!

Seriously, this is C at its finest not really.

As far as I can see, the upcast to unsigned happens because the byte value is leftshifted by eight! That means it's multiplied by 2^8 = 256. As far as I can remember, just unsigned means unsigned int . Only this way, you're able to store the maximum result value of up to 65535.

This way, your first line means "increase a by the sum of k[0] and k[1]*2^8".

Pointer arithmetics work just like in Delphi: If you increase your unsigned char pointer by 12, it's now pointing at the next address 12 bytes "later". In case it had been a pointer to short, it would now have been moved by 24 bytes.

I still don't have the slightest clue what and why is actually happening in this code, but I guess I at least figured out those two lines
  Mit Zitat antworten Zitat