Listing char * (or unsigned char * or typedefs) is a special case and does not cause undefined behavior.
From Specification C, 6.3.2.3 Indices , clause 7:
When a pointer to an object is converted to a pointer to a character type, the result points to the low address byte of the object. Successive increments of the result, up to the size of the object, give pointers to the remaining bytes of the object.
Your first and third examples are covered by this case. The second example is a bit strange, but will probably work on most systems. What you really have to do is either directly read in values :
float values[256]; receive(values, sizeof values);
Or something like this (to avoid alignment problems):
char buffer[1024]; receive(buffer, sizeof buffer); float values[256]; for(int i = 0; i < 256; i++) { char *pf = (char *)&values[i]; memcpy(pf, buffer + i * sizeof(float), sizeof(float)); }
(Note: I changed buffer as a char array - I assume it was a typo in your question).
source share