I am using gcc version 2.7.2 in Linux on a Pentium. I have the following
structure:
typedef struct {
unsigned short msg_type; /* IPC message type */
unsigned long pid; /* sender's process ID */
unsigned short msg_no; /* message number */
unsigned short msg_length; /* including header */
I use this structure as a message header for socket based tcp/ip messageQuote:} IPC_MESSAGE_HEADER;
passing between several machines in a heterogeneous network of Linux,
OS/2 Solaris, and VMS. On Linux (the only place I am using the gcc
compiler), a sizeof(IPC_MESSAGE_HEADER) yields 20 bytes. If you add up
the sizes, you can see that the actual size of the structure should be
10. Runtime dumps of the structure reveal that the compiler sticks 2
extra bytes after the first short.
My assumption is that some automatic word alignment is taking place.
While this may be wonderful for optimization and all that, it is
catastrophic for passing messages between machines whose compilers don't
make these same alignment assumptions.
Most compilers have alignment options. I have check the gcc man pages and
can't find anything. I've tried -mno-strict-align, and -mold-align, but
these abort with the message "invalid option". Also, #pragma align 1
does nothing.
Does anybody have a solution? This is a major problem which is holding
up delivery of software to a customer. Please HELP!
Please email your response if possible.