POV-Ray : Newsgroups : povray.off-topic : Programming language discussion : Re: Programming language discussion Server Time
3 Sep 2024 23:24:58 EDT (-0400)
  Re: Programming language discussion  
From: Nicolas Alvarez
Date: 17 Nov 2010 18:35:51
Message: <4ce466d7@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.