On ARM with GCC 2.95.3:
> uint16 * ptr1 = ( uint16 * ) & buffer[1];
If you lie to a computer, it will get you. You are telling gcc that ptr1 is a valid pointer to uint16, which it isn't.
*ptr1 = 0x1234; // Error, writes into buffer[0-1]
You are lucky it doesn't crash. Writing to a multi-byte item through a mis-aligned pointer invokes undefined behaviour.
How can I force the compiler to generate code, that works correct?
By writing correct code, perhaps?
uint16 val = 0x1234; memcpy(&buffer[1], &val, sizeof(val));
Cheers,