Let’s say I have defined an array float floatBuffer[4] and I have a struct: struct vec3{float x,y,z;} myVec;
before the vec3 assignment, I assign: floatBuffer[3] = 0.0f;
(If this is possible,) In what ways can I assign myVec to floatBuffer[0] (binary copy), so that
-
floatBuffer[0] == myVec.x
-
floatBuffer[1] == myVec.y
-
floatBuffer[2] == myVec.z
-
floatBuffer[3] == 0.0f
?
The obvious answer is:
If you’re willing to make assumptions on struct layout, and your compiler generates crappy code for the direct assignments, document your assumptions and do a
memcpy: