|
![](/i/fill.gif) |
Warp wrote:
> The most clever use of 'union' I have seen was like this:
>
> union Matrix4x4
> {
> double m[4][4];
> struct
> {
> double m11, m12, m13, m14,
> m21, m22, m23, m24,
> m31, m32, m33, m34,
> m41, m42, m43, m44;
> };
> };
>
> This means you can access the matrix like "transform.m[1][2] = 5;"
> or like "transform.m23 = 5;";
>
> Of course in this case this is just a trick to have two naming
> conventions to access the same data (rather than to save memory).
I know someone who got this to work via C++ operator overloading and other
nasties:
Vector3D a, b;
a.xy = b.zx;
It's equivalent to a.x=b.z; a.y=b.x; Any combination of xyz letters would
work, probably even a.xxx=b.yzy;
IIRC it even used SSE inline assembly to do the assignments.
Post a reply to this message
|
![](/i/fill.gif) |