Ethereal-dev: Re: [Ethereal-dev] How to ensure same struct member alignment across compilers?

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <guy@xxxxxxxxxx>
Date: Tue, 20 May 2003 10:50:09 -0700
On Tue, May 20, 2003 at 03:14:59PM +0200, Lars Ruoff wrote:
> when writing structs from memory to binary files, one needs to take care of
> the different padding/alignment strategies among different compilers.
> (for example Visual C++ uses a 4-byte member alignment by default).
> What is the official guideline to deal with that problem?
> Compiler-specific #ifdefs?
> Avoid it completely and write byte by byte in such cases?

The latter is probably the best strategy.  That way, you can also
arrange that the files are written out in a standard byte order so that
the file can be read not only by a program compiled with a different
compiler, but *also* by a program running on a machine with a different
byte order.