Casting a byte array to a struct pointer depends on endianness or memory alignment?

Posted by Petruza on Stack Overflow See other posts from Stack Overflow or by Petruza
Published on 2010-06-02T19:54:36Z Indexed on 2010/06/02 20:34 UTC
Read the original article Hit count: 249

Suppose this code:

unsigned char list[3] = { 1, 2, 3 };
struct _struct{
  unsigned char a;
  unsigned char b;
  unsigned char c;
} *s;
s = ( _struct * ) list; 

Can I assume that always s->a == 1, s->b == 2, s->c == 3 ?
Or it will depend on the system's endianness or memory alignment?

© Stack Overflow or respective owner

Related posts about c++

Related posts about struct