Flexible array members can lead to undefined behavior?
By using flexible array members (FAMs) within structure types, are we exposing our programs to the possibility of undefined behavior? Is it possible for a program to use FAMs and still be a strictly conforming program? Is the offset of the flexible array member required to be at the end of the struct? The questions apply to both C99 (TC3) and C11 (TC1) . #include <stdio.h> #include <stdlib.h> #include <stddef.h> int main(void) { struct s { size_t len; char pad; int array[]; }; struct s *s = malloc(sizeof *s + sizeof *s->array); printf("sizeof *s: %zu\n", sizeof *s); printf("offsetof(struct s,