This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: help: sizeof(struct)
- From: "Claudio Bley" <bley at cs dot uni-magdeburg dot de>
- To: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Tue, 16 Jul 2002 11:19:49 +0200
- Subject: Re: help: sizeof(struct)
- References: <GZBMHQ00.EL5@mail.i-net.com.cn>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
>>>>> "lium" == lium <lium@i-net.com.cn> writes:
lium> Hi, there is a struct like following:
lium> struct test { unsigned char a; unsigned int b;
lium> unsigned char c; } my target machine is ARM7TDMI, my gcc
lium> version is: "gcc version 3.0". when i use sizeof(struct
lium> test), it return 0xc. if i add 'packed' attribute, sizeof
lium> return 6. but i need the sizeof macro return 9.
You may use the following code:
struct test {
unsigned char a ;
int : 24; /* unused */
unsigned int b;
unsigned char c;
} __attribute__((__packed__));
HTH
Claudio
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.6 <http://mailcrypt.sourceforge.net/>
iD8DBQE9M+U1TpSishmp0ioRAgoDAJ9/z6y3gex7k2v9/vsv+2nNUlx2ngCdHpNX
ptM859EgQil6Yie2gmrWPSk=
=4Ul3
-----END PGP SIGNATURE-----