This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: help: sizeof(struct)


-----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-----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]