Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are the structure members stored on a little endian machine?

Tags:

c

struct Dummy {
  int x;
  char y;
};

int main() {
  struct Dummy dum;
  dum.x = 10;
  dum.y = 'a';
}

How would be the layout of the structure members on a little endian machine?

Would it be something like this?

  0x1000  +0   +1   +2   +3
         ___________________
    x:  | 10 |  0 |  0 |  0 |     
         -------------------       
    y:  | 'a'|  0 |  0 |  0 |
         -------------------
  0x1000  +4   +5   +6   +7 
like image 251
Zuzu Avatar asked Mar 27 '11 15:03

Zuzu


1 Answers

I think you'll find this question useful. The endianess is usually relevant for a word in the memory, not to the whole structure.

like image 115
MByD Avatar answered Nov 15 '22 05:11

MByD