Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C gore of the weak

Name: Anonymous 2009-09-11 17:52

1. Does this operation invoke undefined behavior?

union {
  int i;
  struct {
    int i1;
    int i2;
  } s;
} u;

u.i = 3;
printf("%d\n", u.s.i1);

Name: Anonymous 2009-09-12 6:33

>>19
The UB is that you read the value of a member you haven't written to previously, and has nothing to do with struct representation.
It's true that (void *)s == (void *)&s->first_member, but irrelevant.

>>20
but disallows any reordering of struct elements.
Correct. The offsetof macro would be useless without this guarantee.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List