Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Yet another GCC question

Author: Miguel A. Ballicora

Date: 20:38:55 12/05/03

Go up one level in this thread


On December 05, 2003 at 21:24:19, Robert Hyatt wrote:

>I have a structure that looks like this:
>
>struct BOOK_POSITION {
>  long long signature;
>  unsigned int status;
>  float learn;
>  int CAP;
>}
>
>sizeof(above) gives 20 on my dual xeon, 24 on the
>opteron.  I'd like to make it 20 so that my binary book
>can be shared between the opteron and the rest of the
>intel world.
>
>Is there a reasonably portable way to fix this???
>
>(note the long long becomes a long on the opteron, the rest
>are not changed.)

The only portable way to do it is to write the information one byte at a time in
a canonical order. Then, you read it back in the same order, one byte at a time.

I have two functions, be_pack() and be_unpack().
The first one, transforms the bookentry into an array of bytes (unsigned char).
Then I save those in order. The second function, after I read the bytes in order
into an array of bytes, transform them into a bookentry.
I can even save some space because the data is packed as much as I can.

The overhead is negligible compared to the I/O. In that way, my book is
compatible across any system, windows, linux etc and using any compiler.

Miguel




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.