Re:A nice, little known C feature: Static array indices in p...
by mauvehaus on Monday February 18, 2013 @03:46PM
(#5240533)
The compiler doesn't pass any size information when you pass an array into a function. The function just gets a pointer. If you take the sizeof the array, you'll get the size of a pointer on your system:
[eric@rangely foo]$ cat foo.c
#include <stdio.h>
int test (int arr[10])
{
printf ("%lu\n", sizeof (arr));
return 0;
}
int main (int argc, char *argv[])
{
int arr[5];
test (arr);
return 0;
}
[eric@rangely foo]$ cat foo.c
[eric@rangely foo]$ gcc foo.c -Wall -o foo && ./foo8
(EDIT: fixed formatting)