View Single Post
Old Jun 2nd, 2006, 2:40 PM   #6
Animatronic
Programmer
 
Join Date: Jun 2005
Posts: 99
Rep Power: 4 Animatronic is on a distinguished road
Quote:
Even though x came first in the source code, it is stored last in memory. They are however packed titely.
This is because you are putting x,y,z on the stack, so you are just showing how the stack is being implemented on your compiler, nothing to do with how data members in structs are laid out.

The test:

#include <stdio.h>

struct foo
{
	double x,y,z;
};

int main(void)
{
	struct foo f;
	printf("%p,%p,%p\n",&f.x,&f.y,&f.z);

	return 0;
}

shows different.

Good catch on the &x+sizeof(Scalar) != &y thing though.

Quote:
You cant assume that data you define in your source is sequential.
But I think data members have to be sequential in a struct/class to how they're defined.
Animatronic is offline   Reply With Quote