I want to convert a array of uchar to uint8 pointer. As both are of 8 bits and value ranges from 0 to 255 so I do not think it should cause and issue.
uchar list[100];
I have to pass above list to a function which accepts pointer to uint8t. Can i pass it like this :
(uint8t *)list
such that it will not affect the value when i read it as uint8.
Well,
uchar
anduint8_t
are not necessarily the same width ! Technically, a character can be 16bit wide. It is a rare, but it happens, especially in embedded world. So uchar may be not an 8bit type, but uint8 is always a 8bit type.If
uchar
is indeed not a byte, then casting fromuchar []
touint8_t *
eliminates alignment restrictions. For platforms that do not support miss-aligned access (smells like embedded again!) trying to cast like this would be a bug. If you compile withGCC
, add-Wcast-align
flag to catch problems like this.