why cannot assign to function call
Mark Wooding
mdw at distorted.org.uk
Sat Jan 10 14:31:57 EST 2009
rurpy at yahoo.com <rurpy at yahoo.com> wrote:
> What is the observable difference between converting an
> array to a reference (pointer) to that array and passing
> the reference by value, and passing the array by reference?
For one:
#include <stdio.h>
static size_t foo(char v[]) { return sizeof v; }
int main(void)
{
char v[sizeof(char *) * 10];
puts(foo(v) == sizeof(char *) ? "pointer" : "reference");
return (0);
}
For another:
static void bar(char v[]) { char ch = 0; v = &ch; }
/* type error if arrays truly passed by reference */
> I guess the case for pass-by-value would be a little stronger because
> one has to have "passing a pointer by value" anyway (since pointers
> are first-class datatypes) and that can be used to describe passing
> arrays (as you described).
The difference is that the /callee/ function is different between the
two cases.
Also, notice that arrays in expressions turn into pointers in the same
way, so function argument passing works the same way as assignment -- a
hallmark of pass-by-value.
-- [mdw]
More information about the Python-list
mailing list