Most conversions between the types char
, signed char
, unsigned char
, int8_t
and uint8_t
can be regarded as safe. These are the character types and come with various special exceptions that make them more "rugged" than other types.
Specifically, the character types:
- Cannot be misaligned.
- Cannot contain padding bits or trap representations.
- Have exceptions from the effective type/strict aliasing rules.
- Are always of size 1 byte.
Meaning you can do all manner of wild conversions between different character types. With a few exceptions:
- When going from unsigned to signed types the data may not necessarily fit and you'll overwrite the sign bit. This will potentially cause bugs.
- It is dangerous to "cast away"
const
or volatile
qualifiers, if present.
Therefore it is safe to convert from uint8_t*
to char*
and de-reference the data as another type, (char*)uartRX_data
. Especially if you know that the uint8_t
array contains valid 7 bit characters only with MSB never set, and with a null termination in the end of the array.