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?
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?
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.
No, the conversion is legal. However, problems will arise when you try to print data
, because you no longer have a char*
. Other than that the casting is fully supported.