The point I was making earlier about padding means that you can't be sure that a struct will be that size.
Code:
#include <stdio.h>
struct bleh
{
int w;
char x;
float y;
double z;
};
void printsize(const char *, size_t);
int main(void)
{
printsize("int",sizeof(int));
printsize("char",sizeof(char));
printsize("float",sizeof(float));
printsize("double",sizeof(double));
printsize("struct bleh",sizeof(struct bleh));
return 0;
}
void printsize(const char *szType, size_t stType)
{
printf("sizeof(%s) = %d\n",szType,stType);
}
Output when compiled with MinGW, Borland, and LCC on a Windows 32-bit environment:
Code:
sizeof(int) = 4
sizeof(char) = 1
sizeof(float) = 4
sizeof(double) = 8
sizeof(struct bleh) = 24
4 + 1 + 4 + 8 = 17
Yet the struct is padded to be 24 bytes in size.