On 2006-08-04, Gerhard Fiedler <[EMAIL PROTECTED]> wrote:
> On 2006-08-04 15:21:52, Dennis Lee Bieber wrote:
>
>> On Fri, 4 Aug 2006 14:09:15 -0300, Gerhard Fiedler <[EMAIL PROTECTED]>
>> declaimed the following in comp.lang.python:
>> 
>>> Python === C
>>> Textual representation a === Address operator (&a)
>>> id(a) === Dereference operator (*a)
>>> 
>>> I think I didn't quite translate what you meant, but you get the idea. I
>>> don't think you can come up with a working analogy. The differences are
>>> just too many -- if you consider the C language on the right side, not a
>>> custom application you developed in C.
>>>
>>      Closer would be (putting C constructs on left)
>> 
>> c    ~=      id(c)   (address of the object identified by 'c')
>> *c   ~=      c       (dereference to manipulate the object itself)
>> &c   ~=      no Python equivalent for "the address of the name 'c'" 
>> 
>>      C 'c' is a variable, one can take the address of the storage it
>> uses, and manipulate the contents of that storage. One does not have
>> that access with Python name bindings.
>
> But this means that C variables are not analog to Python variables,

Yes they are. Your problem seems to be that you see an int in Python
and want to compare with an int in C.

> C  dereferenced pointers are.

No they are not. a = b in Python translates to: a = b in C. It doesn't
translate to *a = *b in C.

It is true that a = b + c in Python doesn't translate to a = b + c in
C, but since this really is a shortcut of a = b.__add__(c) there
is nothing wrong with tranlating it into something like:
a = IntPlus(b, c) for C, where the IntPlus will provide a new pointer
that points to the sum or we could provide the necessary structures
so that we could translate is as: a = b->__add__(c)

> (c is a C variable; *c is /not/ a C variable,
> it's a dereferenced pointer.) This is what I've been trying to say for a

Which is irrelevant since a = b in Python just translates to a = b in
C. Sure in Python terms we would talk about a and b being ints, while
we would first be tempted to talk about pointers to ints in C. But
since we are talking about variables in general and not about int
variables or pointer variables, that doesn't matter much. If int
variables in Python resemble pointer variables in C then there is
something in C deserving the term variable which behaves like variables
do in Python.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to