R
Rick
Given:
struct x
{
int i;
char c;
}st_x;
int size_of_struct = sizeof( struct x );
int size_of_st_x = sizeof( st_x );
struct x st_array[ 5 ];
int size_of_st_array = sizeof( st_array );
If an int is 32 bits and a char is 8 bits, are there any guarantees as
to what size_of_struct, size_of_st_x, or size_of_st_array evaluate to?
(they could be 5, 5, and 25, or 8, 8, and 40.)
Are there any rules that specify whether compilers are required to
align variables on any specific boundaries?
I tried all of this on gcc on cygwin on Windows XP and got
size_of_struct = 8, size_of_st_x = 8, and size_of_st_array = 40,
rather than what one might expect at first glance, size_of_struct = 5,
size_of_st_x = 5, and size_of_st_array = 25. Am I guaranteed to get
that on all platforms?
If there are any such guarantees, do any of you have a reference to a
document that says so?
Thanks...
struct x
{
int i;
char c;
}st_x;
int size_of_struct = sizeof( struct x );
int size_of_st_x = sizeof( st_x );
struct x st_array[ 5 ];
int size_of_st_array = sizeof( st_array );
If an int is 32 bits and a char is 8 bits, are there any guarantees as
to what size_of_struct, size_of_st_x, or size_of_st_array evaluate to?
(they could be 5, 5, and 25, or 8, 8, and 40.)
Are there any rules that specify whether compilers are required to
align variables on any specific boundaries?
I tried all of this on gcc on cygwin on Windows XP and got
size_of_struct = 8, size_of_st_x = 8, and size_of_st_array = 40,
rather than what one might expect at first glance, size_of_struct = 5,
size_of_st_x = 5, and size_of_st_array = 25. Am I guaranteed to get
that on all platforms?
If there are any such guarantees, do any of you have a reference to a
document that says so?
Thanks...