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]

help: sizeof(struct)


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: Rabbit.GIF
Description: GIF image


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