user6575913 user6575913 - 1 month ago 17
C Question

Pointer conversion in c

I have the following lines:

char *name = malloc(strsize + 1);


and

uint8_t *data;
data = (uint8_t *)name;


It is correct? It doesn't exist a chance that the pointer *name will be interpreted bad when that conversion is done?

Answer

That shouldn't be much of a problem, except that the signedness of the memory would be interpreted differently between access along data and name. In most of the practical platforms, the size of char and uint8_t in bits is the same.

Comments