Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: another simple c question

Author: Aivaras Juzvikas

Date: 07:49:41 07/21/04

Go up one level in this thread


On July 21, 2004 at 09:14:00, Tim Foden wrote:

>On July 21, 2004 at 08:30:33, Daniel Shawul wrote:
>
>>On July 21, 2004 at 06:42:23, Aivaras Juzvikas wrote:
>>
>>>On July 21, 2004 at 06:34:18, Daniel Shawul wrote:
>>>
>>>>On July 21, 2004 at 06:27:06, Paul Clarke wrote:
>>>>
>>>>>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.
>>>>
>>>>Thanks very much.
>>>>I changed the "struct member alignment" to 1 byte. Previously it was
>>>>8 byte. And now it displays the correct size 14.
>>>>Is there any efficiecy loss by changing the alignment?? If there is any
>>>>i don't want to do that?
>>>>
>>>>daniel
>>>
>>>how did u change it?
>>
>>follow the link if you are using MSVC.
>>
>> project -> settings -> c/c++ -> catagory [code generation] -> struct member
>>alignment.
>>
>>daniel
>
>Rather than change the alignment for your whole project, perhaps it would be
>better to just change it for the structures that you require to be packed.
>
>In VC you can use this in your .h file (or wherever the struct is declared):
>
>#pragma pack(push, 1)
>
>struct
>{
>  ....
>};
>
>#pragma pack(pop)
>
>Cheers, Tim.

this didnt work on ms visual c++ .net 2002, any recomendations?it should have
worked because i have some unused bits.



This page took 0 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.