Consider please
#include <stdio.h>
int main(void) {
int size = 1;
int foo[1];
int bar[size];
int* pfoo = 0;
int* pbar = 0;
printf("%zu %zu\n", sizeof(pfoo = foo), sizeof(pbar = bar));
printf("%p %p\n", pfoo, pbar);
return 0;
}
The output when running this on https://ideone.com/VeiJXH is
8 8
(nil) (nil)
I was expecting pbar
to be set to the address of the first element of bar
, as bar
is a variable length array. I thought that sizeof
was evaluated at runtime for variable length arrays, which would mean that pbar
would be non-zero.
What's going on? This is not a quiz; it's a cut down version of a problem that I've encountered in my code.
Edit: I don't think the duplicate helps here - my question is about sizeof not being evaluated for a variable length array.