user6575913 user6575913 - 1 year ago 128
C Question

Pointer conversion in c

I have the following lines:

char *name = malloc(strsize + 1);


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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download