, , . , char - . C. , .
While we are in this state, we can also tidy up the code, make it overly explicit in order to avoid possible errors in the future, delete some implicit declarations such as integer literals, etc.
#include <stdint.h>
uint8_t a[4];
uint32_t addr = 0x0806d3b0UL;
a[0] = addr & 0xFFu;
a[1] = (addr >> 8) & 0xFFu;
a[2] = (addr >> 16) & 0xFFu;
a[3] = (addr >> 24) & 0xFFu;
Masks & 0xFFu, strictly speaking, are not needed, but they can save you from some false positive warnings from the compiler about the wrong integer types. Alternatively, each shift result can be distinguished to uint8_t, and that would be nice too.
source
share