Code:
(*mresult)[0] =  = pos[0] + t*dir[0];


is cleaner, that's how you dereference pointers (although it's basically the same).

since c is pretty eager to convert everything correctly, you could try something like this:
Code:
typedef float *PVECTOR3D;
#define VECTOR3D float[3]

void myfunc(PVECTOR3D pos)
{
    pos[0] = ...
}
...

VECTOR3D mypos;
myfunc(mypos);


what won't work, though, is returning such a VECTOR3D, all it will do is return a pointer to a local variable on the stack which will vanish after the function returns. with typedef'ed variables you'll actually get a copy back. what could work, though, is something like
Code:
typedef struct { float x, y, z; } VECTOR3D;
#define _V(x) (float*)(&(x))

VECTOR3D mypos;
_V(mypos)[0] = ...
return mypos;


but then you could as well just use a struct directly. by the way, what you can do is
Code:
typedef struct { float[3][8] data; } VECTOR3Dx8D;
VECTOR3Dx8D mymatrix;
mymatrix.data[0][1] = ...
return mymatrix;


or, even more elegant, something like
Code:
typedef struct {
    union {
        float[2][2] data;
        struct {
            float xx, xy, yx, yy;
        };
    };
} MAT2x2;


might not work with lite-c, though, unnamed union members don't work in all c compilers.



Last edited by Joey; 03/05/10 10:50. Reason: found something elegant