If uint8_t
exist, is a pointer to uint8_t
equivalent to a pointer to unsigned char
? Means it can be used to access any object and does not cause UB when accessing a different object. I know that this rules:
int intVar=0;
unsigned char *charPtr=&intVar; //completely valid and does not cause UB
printf("%X ",*charPtr); //this is also valid and does not cause UB
struct SomeStruct_T structVar={};
int *intPtr=&structVar; //This causes UB
But what about this:
int intVar=0;
uint8_t *uint8Ptr=&intVar; //Is this valid?
printf("%X ",*uint8Ptr); //If yes, is this also valid?
GCC with -Wincompatible-pointer-types
warns about unsigned char *charPtr=&intVar;
and uint8_t *uint8Ptr=&intVar;
, but with a cast this warning goes away. This does not answer the question.
There is probably no system where uint8_t *
will be different from unsigned char *
but what does the standard say?
This question is about the pointer type which points to unsigned char
or uint8_t
, not about the data type unsigned char
or uint8_t
itself. There are some fundamental properties of unsigned char *
that may or may not apply to uint8_t *
, such as being able to access any object, that are not relevant for the type unsigned char
itself. This question is therefore not a duplicate of the linked question. The linked question is also about C++, but i don't ask about C++, my question is about C. Please do not mark this question as duplicate of the linked question, because the question is definitely not the same.