Questions tagged [out-of-bounds]

1 questions
2
votes
3 answers

Is accessing arrays out-of-bounds legal if what lies beyond those bounds is known in C? Why not and how can this be worked around?

Take the following which works in GCC: union Int2 { int i[2]; }; union Int4 { union Int2 i2[2]; }; union Int4 i4; i4.i2[1].i[-1] = 10; printf("%d\n", i4.i2[0].i[1]); // 10 static_assert(sizeof(Int4)==sizeof(int[4]), "Unexpected…
user16217248
  • 3,119
  • 19
  • 19
  • 37