I'm compiling C code with nested structs for a 3D engine, and curiously the values I'm assigning to the structures are being inverted when the program is run.
Example code:
#include <stdio.h>
struct vertexes // Creates a structure vertexes with 3 coordinates in space
{
unsigned short x, y, z; // 2 bytes variables, restricted to 0-65535
};
struct triangles // Creates a structure triangles
{
struct vertexes vertex[3]; // A triangle is made of 3 vertexes, so we create p arrays of three vertexes
};
main()
{
struct vertexes vertexTest = {1, 2, 3};
printf("x = %d, y = %d, z = %d \n\n", vertexTest.x, vertexTest.y, vertexTest.z);
struct triangles triangleTest = {{{1, 2, 3}, {0, 100, 0}, {100, 100, 0}}};
for (int loop = 0; loop < 3; ++loop)
{
printf ("Loop %d \n", loop);
printf("Vertex coords = %d, %d, %d \n\n", triangleTest.vertex[loop]);
}
}
The output I get:
x = 1, y = 2, x = 3 (which is fine)
Loop 0
Vertex coords = 3, 2, 1 (here lies the problem: I've assigned 1, 2, 3!)
Loop 1
Vertex coords = 0, 100, 0 (well, you can't really invert this)
Loop 2
Vertex coords = 0, 100, 100 (again, inverted: I've assigned 100, 100, 0)
What am I doing wrong?