Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Opening Book

Author: Dieter Buerssner

Date: 12:06:57 03/19/01

Go up one level in this thread


On March 19, 2001 at 04:48:54, David Rasmussen wrote:

>I'm adding opening book support to my engine, but I've got a problem with
>figuring out a good portable book format. I have to be able to store binary
>data, such as a 64-bit hashkey, and I can't see any other way to do this in a
>portable way, than storing one byte at a time in the file, since I don't know
>how ints and other types are represented on various platforms.

I believe you are right, an in C, the only portable way to solve this, is by
looking at the external data on a byte (= [unsigned] char in C) basis.

So if you have

struct bookentry {
  unsigned long count;
  /* and more */
}

Instead of
  struct bookentry be;
  fread(&be, sizeof be, 1, fp);

You have to use something like:

  unsigned char buf[N]; /* N is the length of the structure as defined in the
external layout */
  struct bookentry be;
  fread(buf, 1, N, fp);

  be.count = ((unsigned long)buf[0] << 24)
             | ((unsigned long)buf[1] << 16)
             | ((unsigned long)buf[2] << 8)
             | ((unsigned long)buf[3]) ;

And the same for the other structure members. Something similar for writing.
This will take care of the endianess issue as well as of the possible different
sizes of types (as long, as you do not expect longer sizes than defined in the
ISO standard).

I was too lazy to do like this ... However, the same book will still work for
Linux x86 and Windows (and DOS). I assumed, that anybody should be able to
create a platform specific book from "sources".

Regards,
Dieter




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.