Re: Alignment of variables in structs
- From: jameskuyper@xxxxxxxxxxx
- Date: Thu, 29 Nov 2007 13:01:01 -0800 (PST)
Rick wrote:
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.)
There are some guarantees, just not as many as you thought:
size_of_struct >= sizeof(int)+sizeof(char)
size_of_struct == size_of_st_x
size_of_st_array == 5*size_of_struct
.
- References:
- Alignment of variables in structs
- From: Rick
- Alignment of variables in structs
- Prev by Date: malloc realloc and pointers
- Next by Date: Re: binary search
- Previous by thread: Re: Alignment of variables in structs
- Next by thread: Re: Alignment of variables in structs
- Index(es):
Relevant Pages
|