Allowing struct field to overflow to the next field
问题 Consider the following simple example: struct __attribute__ ((__packed__)) { int code[1]; int place_holder[100]; } s; void test(int n) { int i; for (i = 0; i < n; i++) { s.code[i] = 1; } } The for-loop is writing to the field code , which is of size 1. The next field after code is place_holder . I would expect that in case of n > 1 , the write to code array would overflow and 1 would be written to place_holder . However, when compiling with -O2 (on gcc 4.9.4 but probably on other versions as