Article View: gnu.gcc.help
Article #51496GNU C Compiler Question
From: 0012310
Date: Tue, 11 May 1993 22:16
Date: Tue, 11 May 1993 22:16
62 lines
2624 bytes
2624 bytes
From: Holcomb, Michael J
Date: Tue, May 11, 1993 1:10 PM
Subject: GNU C Compiler Question
To: GNU C Compiler
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:
<9305112211.AA22773@hac2arpa.hac.com>Path:
arc1-ca.pugleaf.net!gmd.de!ira.uka.de!math.fu-berlin.de!cs.tu-berlin.de!mailgzrz.TU-Berlin.DE!news.netmbx.de!Germany.EU.net!mcsun!uknet!pipex!bnr.co.uk!bnrgate!nott!torn!howland.reston.ans.net!usenet.ins.cwru.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,af0546f3bdf62856,start X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1993-05-11 21:27:53 PST Path: arc1-ca.pugleaf.net!gmd.de!ira.uka.de!math.fu-berlin.de!cs.tu-berlin.de!mailgzrz.TU-Berlin.DE!news.netmbx.de!Germany.EU.net!mcsun!uknet!pipex!bnr.co.uk!bnrgate!nott!torn!howland.reston.ans.net!usenet.ins.cwru.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: GNU C Compiler Question Date: 11 May 1993 18:16:34 -0400 Organization: GNUs Not Usenet Lines: 63 Sender: daemon@cis.ohio-state.edu Distribution: gnu Message-ID: <9305112211.AA22773@hac2arpa.hac.com>