4 ms·
You're thinking of flexible or zero-length array members (`int[]` as the terminal field, or mostly equivalently, where supported, `int[0]`). VLAs in a struct on
by scatters 9y ago
You're thinking of flexible or zero-length array members (`int[]` as the terminal field, or mostly equivalently, where supported, `int[0]`). VLAs in a struct only really make sense for a local type i.e. a struct defined and used within a function:
void foo (int n) {
struct S { int x[n]; };
}
https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html
https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
- benmmurphy 9y agothanks. that makes sense. #include <stdio.h> void foo (int n) { struct S { int x[n]; int y; }; printf("offset: %ld\n", __builtin_offsetof(struct S, y)); } int main() { foo(2); foo(16); } offset: 8 offset: 64