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 5:41

>>16
I don't remember the details, but IIRC the standard allows arbitrary between-elements padding (A fact which x86 only programmers seem to be gaily oblivious of, going by the broken code they churn out), but disallows any reordering of struct elements. I suppose it could affect the outcome of some unlikely pointer comparisons, and 'creative' reuse of the end of a struct as storage if there are occasionally unneeded fields.
Certainly you wouldn't want to relocate any flexible array members, but that would be pointless anyway.
-fipa-struct-reorg can do some funky stuff with structures, but the primary goal is to increase loop locality, not to eliminate padding.

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