This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: interesting struct???????????
- To: "Ashok Das" <ashok_s_das at hotmail dot com>
- Subject: Re: interesting struct???????????
- From: Alexandre Oliva <aoliva at redhat dot com>
- Date: 18 Oct 2000 13:31:58 -0200
- Cc: drepper at cygnus dot com, gcc-bugs at gcc dot gnu dot org
- Organization: GCC Team, Red Hat
- References: <F32qSOc7wo95EFk2H3b00000ef7@hotmail.com>
On Oct 18, 2000, "Ashok Das" <ashok_s_das@hotmail.com> wrote:
> struct x{
> int a;
> char b;
> };
> sizeof(struct x) gives 8 why??
It's called padding. `int's are often more efficiently accessed when
they live in an address that is a multiple of the word size (4); some
machines even won't allow you to load or store words unless the
address is a multiple of the word size. If you ever create an array
of `struct x', you'd want the `a's to be stored in appropriate
addresses, and sizeof is designed such that:
sizeof(TYPE[n]) == n * sizeof (TYPE)
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me