Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: another simple c question

Author: Paul Clarke

Date: 03:27:06 07/21/04

Go up one level in this thread


On July 21, 2004 at 06:16:10, Daniel Shawul wrote:

>
>Isn't the size of a struct the sum of the sizes of its members.
>
>but for this struct sizeof(HASH_E) gives me 16 when i expect 14
>
>struct HASH_E
>{
>	HASHKEY checksum;
>	char     from;
>	char     to;
>	short    eval;
>	unsigned char    depth;
>	unsigned char    entry_threat_promote_seq;
>};

Structures are padded so that their size is a multiple of the largest alignment
size required by any of the members. In this case that would be the HASHKEY
which, depending on your architecture, the compiler will probably want to align
on a four- or eight-byte boundary, so the compiler adds a couple of extra bytes
to make the structure a multiple of four or eight bytes. The idea is that, if
you have an array of these structs, all the fields in all the elements of the
array will have the required alignment.



This page took 0.01 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.