Author: Eugene Nalimov
Date: 19:02:19 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 problem is not that sizeof(struct) == 24 on x86-64. The problem is that
sizeof(struct) == 20 on x86.
On 64-bit architectures you need 8-bytes alignment for structure that contains
64-bit data, otherwise you'll end up with slower accesses (best case) or
exceptions on unaligned data. It looks that support for 64 bit data was added to
32-bit GNU compiler without thinking about binary compatibility in mind.
sizeof(struct) == 24 on Visual C for any platform, so there should be no
problems with interoperability under all Windows dialects.
You probably can live with something like
typedef char my_struct[24];
#define signature(x) (*(long long *)&(x[0]))
#define status(x) (*(unsigned int *)&(x[8]))
#define learn(x) (*(float *)&(x[12]))
#define CAP(x) (*(int *)&(x[16]))
That is ugly, but should work as long as (sizeof(long long) == 8) and
(sizeof(int) == 4), but I expect problems on some strange architectures.
Thanks,
Eugene
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.