5 ms·
It's probably silly to start remote-lawyering with Mr Torvalds of all people, but that is obviously false, and (also obviously) he knows it. If it acts exactly
by unwind 3y ago
It's probably silly to start remote-lawyering with Mr Torvalds of all people, but that is obviously false, and (also obviously) he knows it.
If it acts exactly like a function, show me its prototype, and how you would call it through a function pointer. I'll be here, waiting while thumbing through my old K&R, or something ...
Also, when using variable-length arrays (which are being phased out, but they are in for instance C99) this works:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
size_t arglens[argc];
for (size_t i = 0; i < sizeof arglens / sizeof *arglens; ++i) {
arglens[i] = strlen(argv[i]);
}
printf("Computed %zu lens:\n", sizeof arglens / sizeof *arglens);
for (size_t i = 0; i < sizeof arglens / sizeof *arglens; ++i) {
printf("%zu: '%s' is %zu\n", i, argv[i], arglens[i]);
}
return 0;
}
Compile (as C99!) and run:
$ gcc -o arglens -std=c99 arglens.c
$ ./arglens foo bar baz fooofooofoo
Computed 5 lens:
0: './arglens' is 9
1: 'foo' is 3
2: 'bar' is 3
3: 'baz' is 3
4: 'fooofooofoo' is 11
Notice how sizeof is computing the size of a run-time sized array. Very much unlike a function.
Edit: fix indent for code formatting (hard tabs don't work).