Vanilla List Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [VANILLA-LIST:3131] Binary portability
On Sat, May 06, 2000 at 11:27:54AM -0400, Jeffrey Nowakowski wrote:
>
> > You may be getting an extra byte swap in the cambot file. Since I haven't
> > looked at the server and client cambot code, I couldn't say for sure.
>
> There shouldn't be any swapping done, because the packets that are
> written to the cambot file have not gone through the network.
Packets are constructed in network byte order but stored (and saved to file)
in host byte order. When this file is read by another machine, there may
be an extra byteswap that is needed.
> > Binary file portability deals with endianness, data type sizes, alignment,
> > padding, etc, etc, etc. Fortunately for netrek, most of these issues
> > are avoided with the exception of endianness.
>
> How are they avoided? Isn't it up to the compiler on a particular
> platform to determine all the stuff you mentioned above? What about
> 64 bit machines?
These problems are avoided because netrek packets are 32 bit aligned. On
64 bit machines, 64 bit alignment only comes into play when you have 64 bit
words. Netrek does not use 64 bit words, so it is irrelevant.
It is up to both the CPU architecture and the compiler to address the issues
of alignment, padding, etc.
> Essentially what I am hearing is that client and server recordings are
> not compatible across different endian machines, and we are just lucky
> that we don't run into other issues such as alignment.
The alignment issues are not relevant because the packets structures are
explicitly padded and aligned in the netrek code. I wouldn't call that
luck...
> My compiler is leaving holes in structures, which is wasting space and
> preventing ``binary'' I/O to external data files. Can I turn off the
> padding, or otherwise control the alignment of structure fields?
>
> Your compiler may provide an extension to give you this control
> (perhaps a #pragma; see question 11.20), but there is no standard
> method.
Or you can simply add padding dummy variables and order the structure so
that boundary alignment is explicit. This is what netrek does.
--
Dave Ahn <ahn@vec.wfubmc.edu> | "When you were born, you cried and the
| world rejoiced. Try to live your life
Virtual Endoscopy Center | so that when you die, you will rejoice
Wake Forest Univ. School of Medicine | and the world will cry." -1/2 jj^2