[OpenAFS-devel] -current, offsetof and irix

Nickolai Zeldovich kolya@MIT.EDU
Thu, 24 Jan 2002 15:19:49 -0500


> it seems the irix compiler doesnt like the way that offsetof was used in
> src/rx/rx.h:
> [..]
> #define rx_AckDataSize(nAcks) (3 + offsetof(struct rx_ackPacket, acks[nAcks]))

Probably something like this would work equally well:

  #define rx_AckDataSize(nAcks) (3 + nAcks + offsetof(struct rx_ackPacket, acks[0]))

The problem with the original definition, which used sizeof(rx_ackPacket),
is that the compiler added 3 bytes of padding to the struct in order to
maintain 32-bit alignment, which also added 3 bytes of padding to the ack
packet between the ack section and the trailing MTU/etc fields.  The new
#define was intended to make this fact more obvious, and more portable to
other platforms in the future.  (The use of sizeof was probably a mistake
to begin with, but now existing Rx code requires those 3 spare bytes.)

-- kolya