help: sizeof(struct)

lium@i-net.com.cn lium@i-net.com.cn
Mon Jul 15 19:49:00 GMT 2002


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.

	                 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: Rabbit.GIF
Type: image/gif
Size: 1488 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20020715/87b1aa3f/attachment.gif>


More information about the Gcc-help mailing list