poita said:
Well, "contiguously" means "without gaps in between". If there was padding in between objects (due to alignment) then they wouldn't be contiguous. I guess it's arguable whether the 4 bytes of padding at the end are part of the object or not, but that's what I was getting at :)
I guess the real question is, should I rely on it? Some of you are saying I should and others that I shouldn't.
I don't think it's all that arguable. Although I haven't checked the standard in my experience the padding is not
between objects, it's
part of the object. Take the sizeof() of your object and you will see this. Therefore the objects themselves are contiguous. As an example I compiled this code in Visual C++:
#include "stdafx.h"
#include <stdio.h>
struct Vec3 { float x, y, z; };
struct Vec4 { double x; float y; };
int main()
{
printf("sizeof(Vec3)=%d\n",sizeof(Vec3));
printf("sizeof(Vec4)=%d\n",sizeof(Vec4));
return 0 ;
}
results are:
sizeof(Vec3)=12
sizeof(Vec4)=16
The space required should be the same but because the compiler does double alignment for the Pentium to avoid bus performance issues, the size of the Vec4 is larger. I worked at intel for over 20 years and we compiled code on a tons of different workstations from different venders. Trust me, you shouldn't use pointers like that if you want things to be portable.