What other languages use the same data model as Python?

Grant Edwards invalid at invalid.invalid
Wed May 4 16:19:05 EDT 2011


On 2011-05-04, harrismh777 <harrismh777 at charter.net> wrote:
> Hans Georg Schaathun wrote:

>> In C it is pass by value, as the pointer is explicit and do whatever
>> you want with the pointer value.
>
> You clearly are not a C programmer.
>
> Most of my C data abstractions use dual circular linked lists of 
> pointers to structures of pointers. *All* of that is only ever passed
> (at least in my programming) as references. My code almost never
> passes data by value.
>
> We do not consider passing a pointer as *by value* because its an 
> address; by definition, that is pass-by-reference.

No, it isn't.  It's pass by value.  The fact that you are passing a
value that is a pointer to another value is not relevent.

Pass by reference means that if I call

  foo(x)

And foo looks like this:

  foo(param)
    param = 4

Then 'x' in the caller's namespace ends up set to 4.    

> We are not passing the *value* of the data, we are passing the memory
> location (the reference) to the data.

You're pass a value.  That value is a pointer to some other value.

> Pass by *value* on the other hand actually places the *value* of the
> data item on the call stack as a parameter.

C is pass by value.

if I call foo(x)

And this is foo:

void foo (float param)
{
  param = 1.23
}

The value of x in the caller's namespace is not changed.  If C used
pass by reference, x would change.

-- 
Grant Edwards               grant.b.edwards        Yow! SHHHH!!  I hear SIX
                                  at               TATTOOED TRUCK-DRIVERS
                              gmail.com            tossing ENGINE BLOCKS into
                                                   empty OIL DRUMS ...



More information about the Python-list mailing list