'Is there any way to reference floats as a glm::vec3

I have floats in a context

float* floats = calloc(3, sizeof(float));
float& x = floats[0];
float& y = floats[1];
float& z = floats[2];

How do I assign them to a glm::vec3 such that I can perform operations on them? Is it really a matter of:

glm::vec3 vertex = { x, y, z };
// Transform and Rotate vertex
X = vertex.x;
y = vertex.y;
z = vertex.z;

Or is there a way I can bind the values to the vec3



Solution 1:[1]

Casting to a vec3 worked as expected, with the underlying floats changing when I changed the vec3 values.

vec3& vertex = (*reinterpret_cast<vec3*>(floats));
vertex.x = 1;
assert(floats[0] == vertex.x);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ?aeun acreĆ”?