In doing 3D, each matrix should be the same size so this does not matter.

Code:

void MatrixMultiply(double matrix1[4][4],double matrix2[4][4],double result[4][4])
{
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++)
{
result[i][j]=0;
for (int k=0;k<4;k++)
{
result[i][j]+=(matrix1[i][k]*matrix2[k][j]);
}
}
}
}

If you want it to be a bit faster concatenating then unroll the second loop.

Code:

void MatrixMultiply(double matrix1[4][4],double matrix2[4][4],double result[4][4])
{
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++)
{
result[i][j]=((matrix1[i][0]*matrix2[0][j])
+ (matrix1[i][1]*matrix2[1][j])
+ (matrix1[i][2]*matrix2[2][j])
+ (matrix1[i][3]*matrix2[3][j]));
}
}
}

Unrolling the first or second loop will not give you any significant speed gains.

I'm not sure exactly what OpenGL does with its matrices or how it concatenates them. Seems that every program does it a bit different than the next.

AFAIK, you cannot multiply matrices of different sizes - you cannot correctly concatenate matrices of unlike sizes. In using matrices your vertexes must be in the form x,y,z,t and your final screen coords will be x,y,t. The t is just so that the math comes out right and should always be 1. The only way I know that you could try to concatenate diff sizes is to change the i and j values in the for loop, but it will still not come out right mathematically.

Perhaps there was a misprint on the page.