module confusion

Neil Cerutti horpner at yahoo.com
Fri Oct 5 14:47:54 CEST 2007


On 2007-10-05, Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> wrote:
> In message <slrnfg9ru0.1lk.horpner at FIAD06.norwich.edu>, Neil Cerutti wrote:
>
>> On 2007-10-03, Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand>
>> wrote:
>>> In Python, all names _are_ variables. They are not "bound" to
>>> objects. The value of os.path is a pointer. It's implemented
>>> as a pointer, it has all the semantics of a pointer.
>> 
>> No. A pointer is also an iterator.
>> 
>> void duplicate(char *d, const char *s)
>> {
>>   while (*d++ = *s++)
>>     ;
>> }
>
> So if you can't do pointer arithmetic, then it's not a pointer?
> Trying this:
>
>     void duplicate(void *d, const void *s)
>     {
>       while (*d++ = *s++)
>         ;
>     }
>
> I get:
>
>     test.c: In function 'duplicate':
>     test.c:3: warning: dereferencing 'void *' pointer
>     test.c:3: warning: dereferencing 'void *' pointer
>     test.c:3: error: invalid use of void expression
>
> So you can't do arithmetic or iterate with a void * pointer.

...or dereference.

> Does that mean it's not really a pointer?

That's an interesting taxonimical conundrum. If a pointer were
defined by it's semantics, then yes, a void pointer wouldn't be a
pointer. But pointers are defined not by behavior, but by an
ANSI/ISO standard. The term "pointer to void" makes sense if you
think of it as a pointer in an altered, intermediate state.

I suppose you might score a Pyrrhic victory by claiming that
Python identifiers are pointers that don't behave like pointers.
But you claimed the opposite.

-- 
Neil Cerutti



More information about the Python-list mailing list