|
|
|
|
|
by dllthomas
3461 days ago
|
|
I don't see how the code assumes anything about the placement of the array. Indeed, it works just fine for static arrays: $ cat test.c
#include <stdio.h>
int arr[5];
int main(int argc, char *argv[]) {
printf("%lu, %ld\n", sizeof(arr) / sizeof(*arr), (&arr)[1] - arr);
}
$ gcc test.c && ./a.out
5, 5
Not saying it's "a good way to program" - it's needlessly obfuscated compared to the standard sizeof alternative. But it doesn't rely on anything tricky. |
|