# Problem in Beginner Board

I’m sorry to call you here.
After that discussion about matrices I’m beginning to think I’m doing it all wrong with the matrices. Could anyone of you be so nice to judge who’s right?
It’s not that I want to know that I’m right or wrong, it’s because I don’t think that the discussion comes any further, and I’d correct my engine as soon as possible.

Thanks.

To answer what is going on there:

1. It is unsafe to declare an opengl matrix as m[4][4]. I have first hand knowledge that C++ does not guarantee contiguous memory if you do this. Use m[16].

2. You are correct, Michael. OpenGL lays out matrices like this:

0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15

Which is the transpose of the way one normally sees it done in programming.

Zeno

C++ is required by the language standard
to allocate contiguous memory for a
declaration of multi-dimensional arrays.

float g[4][4];

sizeof(g) == 44sizeof(float);

Perhaps you mean that the C language puts
what we traditionally thinks of as “x” in
the last pair of brackets, because it has
different row/column ordering than Fortran?

Yeah, opengl is column major, but C/C++ are row major.

So if you have a matrix M like that :

1 2 3
4 5 6
7 8 9

then M[i][j] will be like that in memory
1 4 7 2 5 8 3 6 9

but C/C++ have that reprensentation when you do M[i][j]

1 2 3 4 5 6 7 8 9

So you just need to allocate a one-dimensional array just like Zeno said and make your own little M(i,j) function.

If you are using VC++, you could get non-contiguous memory for float m[4][4], for example. I know Microsoft violates all sorts of C++ standards, so this could be one of them…

Neil:
If you are using VC++, you could get non-contiguous memory for float m[4][4], for example. I know Microsoft violates all sorts of C++ standards, so this could be one of them…

Nonsense.

btw, about MSVC - in despite of some bugs, it is the one of the best C++ compilers, and the best IDE indeed.

[This message has been edited by Serge K (edited 01-13-2001).]

Neil:

> If you are using VC++, you could get non-
> contiguous memory for float m[4][4], for
> example. I know Microsoft violates all
> sorts of C++ standards, so this could be
> one of them…

I will choose to dis-believe you until you
can show me a piece of code which violates
this part of the standard.

Note that this is VERY fundamental to how
the C/C++ languages work; any compiler
getting this wrong wouldn’t get two feet in
a language validation test.

The most annoying bug in MSVC++ is the old-
style scoping for for index variables. And
while you can turn that off by disabling
don’t compile without those language
extensions enabled. Feh!

Originally posted by Neil:
If you are using VC++, you could get non-contiguous memory for float m[4][4], for example. I know Microsoft violates all sorts of C++ standards, so this could be one of them…

This is a rediculous statement. Its like saying that because there are errata in pentium processors, any time a program crashes it is because of the processor.

Please provide me a VC++ project that shows that for (edited: oops, didnt do this right last time)
float myvar1[sizeA][sizeB];
float myvar2[sizeAsizeB];
//file myvar1 with data here
memcpy(myvar2, myvar1, sizeof(float)sizeAsizeB);
(myvar1[x][y] != myvar2[x
sizeB+y])

the last statement is true. You wont be able to do it.

[This message has been edited by LordKronos (edited 01-13-2001).]