Re: querry related to structure padding
- From: "santosh" <santosh.k83@xxxxxxxxx>
- Date: 18 Mar 2006 23:34:58 -0800
Jack Klein wrote:
On 18 Mar 2006 19:34:22 -0800, "Lalatendu Das" <lalatdas@xxxxxxxxx>
wrote in comp.lang.c:
hi let's say i have a structure
struct test {
int A;
char B[5];
int C;
};
this above structure defination always going to take 16 byte in
memeory in whatever manner we align the member variables while
declaring a variable to it .
No, you are completely wrong. It is going to occupy sizeof(struct
test) bytes in memory, no more and no less.
On two different compilers that I use that will be exactly 7 bytes. On
several other compilers that I use that will be 9 bytes, while on
others it will be 10.
because variable 'A' going to take 4 byte then four charachter of
Variable 'A' is going to occupy sizeof(int) bytes. On various
compilers that I use, that varies between 1 and 4 bytes. There may or
may not be padding bytes after 'A'.
array gonna take another 4 bytes but the remaining will take also 4
bytes due to four byte alignment nature of compiler .
and last four byte by integer C .
No, the array 'B' will not take 4 bytes and another 4 bytes, that is 8
bytes in total. Unlike everything else in your post, this is one
thing that is absolute. The array 'B' will occupy exactly 5 bytes, on
your compiler and on every C compiler that ever existed.
There might be padding bytes after 'B' before the start of the next
member. Perhaps that is what you are talking about. Those padding
bytes do not change the size of 'B', an array of 5 char will always
have a size of exactly 5 bytes.
Dumb question:
A "byte" need not be 8 bits in size, though it is under PCs right?
.
- Follow-Ups:
- Re: querry related to structure padding
- From: Keith Thompson
- Re: querry related to structure padding
- References:
- querry related to structure padding
- From: Lalatendu Das
- Re: querry related to structure padding
- From: Jack Klein
- querry related to structure padding
- Prev by Date: Re: array greater than 100
- Next by Date: Re: querry related to structure padding
- Previous by thread: Re: querry related to structure padding
- Next by thread: Re: querry related to structure padding
- Index(es):
Relevant Pages
|