Why does the C standard not mention any UB in its definition of offsetof()? Is it implicit somewhere else that doing offsetof(struct foo, arr[SIZE_MAX])
on a struct containing a flexible array member is UB?
Both GCC and clang don't diagnose anything here and compile it to a "return 0":
#include <stddef.h>
#include <inttypes.h>
struct foo {
int a;
int arr[];
};
unsigned long func(void) {
return offsetof(struct foo, arr[SIZE_MAX]);
}
https://godbolt.org/z/rx7rqvh7j