sizeof(array)
Seth Robertson
seth at ctr.columbia.edu
Tue Aug 22 12:48:08 AEST 1989
Hi.
I have a problem in that when I pass an array, it loses track of its size.
ex.
------------------------------------------------------------------
unsigned long testcode[] =
{
3422617600,
3422752768,
513998896,
2684354560,
0 };
main()
{
int size = sizeof(testcode) / sizeof(testcode[0]);
printit(testcode);
printf("Loading %d %d %d\n",size,sizeof(testcode),sizeof(testcode[0]));
}
printit(code)
unsigned long code[];
{
int size = sizeof(code) / sizeof(code[0]);
printf("Loading %d %d %d\n",size,sizeof(code),sizeof(code[0]));
}
----------------------------------------------------------------------
Output:
Loading 1 4 4 <-- Incorrect
Loading 5 20 4 <-- Correct
I guess I understand what it is does (only passing the address, not any
additional information), but how do I get it to do what I want?
In case you are wondering, yes, there are good reasons for making
`printit' a subroutine, for passing code as a parameter instead of
explicitly naming testcode, and for making testcode a global
automatically initialized variable (variable only at compile time,
obviously) sized array.
--
-Seth Robertson
seth at ctr.columbia.edu
More information about the Comp.lang.c
mailing list