On Thu, Apr 2, 2009 at 4:05 PM, Michael Sullivan <[email protected]> wrote:
[..]
> Still, the called function would have a pointer to the passed-in array
> and would know its type, so couldn't it still do the sizeof thing?
All it has is a pointer to the first element of the array - (you're
not passing the array since it decays into a pointer) - it has no
other knowledge of the array. All sizeof is going to return is the
size of a pointer, not the sizeof the array - assuming it was indeed
an array that was passed. Consider:
void foo(char* array){
[...];
}
char x[] = "Hello world";
char* y;
y = malloc(128);
strcpy(y, "Hello world");
foo(x);
foo(y);
sizeof(x) has meaning here - sizeof(y) doesn't, yet both may be passed
to foo() - which cannot do sizeof() anything other than the pointer.
--
PJH
http://shabbleland.myminicity.com/tra
http://www.chavgangs.com/register.php?referer=9375