[comp.unix.xenix] #pragma pack

ORCUTT@cc.utah.edu (11/19/89)

I am trying to port a large application from PC-DOS to
XENIX.  The application was made with structure packing
on (-Zp in the Microsoft compiler for PC's) and depends
on structure elements being next to each other.  On PC-DOS
the include files that define structures are bracketed
by #pragma pack(2) and #pragma pack() to cause the
structures used by library functions to be defined
in the same way they were when the library functions
were compiled.  The pack(4) overrides whatever packing
was specified by -Zp on the compiler command line
and the pack() restores it.  In XENIX, the include
files enclose the #pragma pack(N) directives in
#ifdef's to test whether the target processor is an
8086, 80286, or 80386.

The compiler that came with my XENIX-386 rel.
2.32 seems to ignore the #pragma pack(4)
directives that appear in some of the include files
(such as <stdio.h>) and doesn't have them in some
of the files that need them (such as <sys/stat.h>
and <sys/statfs.h>).  As a result, the stat()
and statfs() system calls don't work when the
calling function is compiled with -Zp and any
functions that explicitly use stdout and stderr
(like the putchar macro) don't work either when
compiled with -Zp.  I have worked around this by
adding dummy entries in the structures defined in
the include files that explicitly put the padding
in the structures where the #pragma pack(4) would
put it.  If you need to use -Zp, you will have to
do this, too.

I sent a report of this to SCO.