Article View: gnu.gcc.help
Article #51443Packed Structures
From: 0012310
Date: Mon, 17 May 1993 15:24
Date: Mon, 17 May 1993 15:24
61 lines
2509 bytes
2509 bytes
From: Holcomb, Michael J
Date: Mon, May 17, 1993 7:58 AM
Subject: Packed Structures
To: GNU GCC; GNU
I am using the GNU C compiler running on the SUN for a target MC68040
processor. I would like to know if there is a way to specify that structures
be packed on 1-byte boundaries. I am working with the following structures:
typedef struct
{
unsigned Start_Byte : 8;
unsigned Message_Type : 8;
} Message_Header_Type;
typedef struct
{
unsigned Checksum_0_6 : 8;
unsigned Checksum_7_13 : 8;
unsigned End_Byte : 8;
} Message_Trailer_Type;
typedef struct
{
unsigned Bute_1 : 8;
unsigned Byte_2 : 8;
unsigned Byte_3 : 8;
} Message_Body_Type;
typedef struct
{
Message_Header_Type Message_Header;
Message_Body_Type Message_Body;
Message_Trailer_Type Message_Trailer;
} Output_Message_Type;
Using the 'sizeof' operator on each of the above structures gives me the
follow results:
sizeof (Message_Header_Type) = 2
sizeof (Message_Body_Type) = 4
sizeof (Message_Trailer_Type) = 4
sizeof (Output_Message_Type) = 10
It seems that any structure with an odd number of bytes get padded with an
extra byte so that it stays aligned on a word boundary. This extra padding
byte on the two Message_Boby and Message_Trailer structures is causing
problems in my coding application.
Most compilers have a 'pack' or 'align' specifier to cause structure members
to be packed into memory on 1-byte, 2-byte, or 4-byte boundaries. If your
complier has any switches or a #pragma preprocessor directive to force 1-byte
packing please let me know. Your assistance to my problem would be
appreciated.
Thank You,
Mike Holcomb
Hughes Aircraft Company
P.O Box 3310 M/S 604/E222
Fullerton, CA 92634
Internet 0012310@msgate.emis.hac.com
Technical Details
Message-ID:
<9305171459.AA16731@hac2arpa.hac.com>Path:
arc1-ca.pugleaf.net!gmd.de!Germany.EU.net!mcsun!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!msgate.emis.hac.COM!0012310Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,6d5d91928bc29eae,start X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1993-05-17 08:44:06 PST Path: arc1-ca.pugleaf.net!gmd.de!Germany.EU.net!mcsun!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!msgate.emis.hac.COM!0012310 From: 0012310@msgate.emis.hac.COM Newsgroups: gnu.gcc.help Subject: Packed Structures Date: 17 May 1993 11:24:04 -0400 Organization: Gnus Not Usenet Lines: 62 Sender: daemon@cis.ohio-state.edu Distribution: gnu Message-ID: <9305171459.AA16731@hac2arpa.hac.com>