Why is sizeof(XID)==8 on AMD64?
Matthieu Herrb
matthieu.herrb at laas.fr
Mon Mar 28 07:56:04 PDT 2011
On Mon, Mar 28, 2011 at 04:47:18PM +0200, Clemens Eisserer wrote:
> Hi Matthieu,
>
> Thanks for your explanation =)
>
> > This is a mistake done 25 years ago or so. It's hard to justify it,
> > but it is so. A number of things that are 32 bits on the wire
> > are represented as 64 bits long at the API level on LP64 machines.
>
> Is it considered more or less safe to store those 64-bit XIDs in 32bit
> variables?
Since they are 32 bits values at the protocol level, yes.
> If not really required I would prefer not to change all my code.
But be careful everytime you pass your 32 bit variables to X functions
that expect 64 bit values, especially when a pointer to such a
variable is used (like in XChangeProperty() that I mentionned above).
On little endian architectures with weak alignment constaints passing
a pointer to a 32 bit only value won't harm too much since the low 32
bits will be used as expected.
But on big endian architectures, it will use the the 32 higher bits of
the value you're pointing to, which are not well defined...
And if your architecture as strict aligment constraints for 64 bits
values, passing a pointer to a 32 bit data has great chances to
produce an unaligned access error.
--
Matthieu Herrb
More information about the xorg
mailing list