typedef float mat4[4][4]; void mat4_set(mat4 m) { for (int y = 0; y < 4; ++y) { for (int x = 0; x < 4; ++x) { m[y][x] = y * 4 + x; } } } template<typename T, size_t Y, size_t X> struct matrix_traits { typedef T pointer[Y][X]; }; template<typename T, size_t Y, size_t X> inline typename matrix_traits<T, Y, X>::pointer& matrix_ptr(T* p) { return *reinterpret_cast<typename matrix_traits<T, Y, X>::pointer*>(p); } void test() { float m[16] = { 0 }; //mat4_set(matrix_ptr<float, 4, 4>(m)); mat4_set(*reinterpret_cast<float(*)[4][4]>(m)); for (int i = 0; i < 16; ++i) { printf("%f\n", m[i]); } }
sdragonx https://github.com/sdragonx