[Haskell-cafe] Specify array or list size?

Hamilton Richards ham at cs.utexas.edu
Sat May 7 16:25:26 EDT 2005


At 12:04 PM -0700 2005/5/7, Jacob Nelson wrote:
>GCC knows how big an array is:
>
>jake$ cat > arrsizetest.c
>#include <stdio.h>
>
>int main()
>{
>         int a[50];
>         printf("sizeof a == %d\n",sizeof(a));
>         return 0;
>}
>jake$ gcc arrsizetest.c
>jake$ ./a.out
>sizeof a == 200
>
>jacob
>

gcc knows the size of an array variable only in the scope of its definition:

#include <stdio.h>

void f( int x[] )
{
         printf("f:    sizeof a == %d\n",sizeof(x));
}

int main()
{
         int a[50];
         printf("main: sizeof a == %d\n",sizeof(a));
         f( a );
         return 0;
}

ham% gcc arrsize.c
ham% a.out
main: sizeof a == 200
f:    sizeof a == 4

Cheers,

--Ham



More information about the Haskell-Cafe mailing list