Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Sat Oct 18, 2014 9:38 am |
|
|
Quote: |
Is it because my pointer is int16 and it points to 2 bytes -> to value8bits and the one of value16bits?!
|
I wouldn't say 'correct' to this.
You are telling the compiler that the pointer points to an int16, and then pointing it 'at' an int8 value. When you update the value, it updates the int16 value pointed to, which also then includes the low byte of the next variable....
'value16bits', does not enter the equation, except as the value that incorrectly gets overwritten by the second byte of the int16 value.
int8 *pointer;
Will still have 'pointer' as a 16bit value, but the compiler then knows it points at an 8bit target.
The int16, in the pointer declaration, is not the size of the pointer, but the size of the variable it addresses.
int8 *pointer;
float *pointer;
int16 *pointer;
int32 *pointer;
All declare a pointer of exactly the same size, but if you write a value to each, for the first 4bytes are written to, the second and fourth, four bytes, and the third two bytes.
The 'size' in a pointer declaration, is not the size of the pointer, but what it addresses. |
|