public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* help: sizeof(struct)
@ 2002-07-15 19:49 lium
  2002-07-16  2:19 ` Claudio Bley
  0 siblings, 1 reply; 2+ messages in thread
From: lium @ 2002-07-15 19:49 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1499 bytes --]

Hi,
	
	there is a struct like following:
	
	struct test {
		unsigned char a;
		unsigned int b;
		unsigned char c;
	}
	my target machine is ARM7TDMI, my gcc version is: "gcc version 3.0". when i use sizeof(struct test), it return 0xc. if i add 'packed' attribute, sizeof return 6. but i need the sizeof macro return 9. 
	
    the follow is memory layout:                    
                                                    
Normal: +---+---+---+---+  Packed: +---+---+---+---+
        |///|///|///|///|          |///|///|///|///|
        +---+---+---+---+          +---+---+---+---+
        | a |   |   |   |          | a | b | b | b |
        +---+---+---+---+          +---+---+---+---+
        | b | b | b | b |          | b | c |///|///|
        +---+---+---+---+          +---+---+---+---+
        | c |   |   |   |          |///|///|///|///|
        +---+---+---+---+          +---+---+---+---+
                                                    
Wanted: +---+---+---+---+                           
        |///|///|///|///|                           
        +---+---+---+---+                           
        | a |   |   |   |                           
        +---+---+---+---+                           
        | b | b | b | b |                           
        +---+---+---+---+                           
        | c |///|///|///|                           
        +---+---+---+---+         

	would you please tell me which compiling option can do so.

	                 



[-- Attachment #2: Rabbit.GIF --]
[-- Type: image/gif, Size: 1488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: help: sizeof(struct)
  2002-07-15 19:49 help: sizeof(struct) lium
@ 2002-07-16  2:19 ` Claudio Bley
  0 siblings, 0 replies; 2+ messages in thread
From: Claudio Bley @ 2002-07-16  2:19 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-07-16  9:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-15 19:49 help: sizeof(struct) lium
2002-07-16  2:19 ` Claudio Bley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).