Finding the instance reference of an object [long and probably boring]
grante at visi.com
Sun Nov 9 02:12:55 CET 2008
On 2008-11-08, Terry Reedy <tjreedy at udel.edu> wrote:
> Steven D'Aprano wrote:
>> In an attempt to keep this post from hitting the ridiculous length of one
>> (Aside: I've learned one thing in this discussion. Despite the number of
>> sources I've read that claim that if you pass an array to a C function
>> the entire array will be copied, this does not appear to be true....)
> Since C does not have an array type, it is impossible to pass an array.
> int *a, b declares *both* a and b as int pointers. As I remember,
> the only difference is that b is initialized to the address of an
> allocated block of 10.
No, that's not true. "b" is not a pointer that's initialized
with an address. "b" is a constant literal that is equivalent
to the address of the first element in the "array". IOW,
(void*)b == (void*)&b == (void*)&b.
That's not true for a. (void*)a == (void*)&a,
but (void*)a != (void*)&a.
> In expressions, b is an int pointer, just like a, and a[i] and
> b[i] are defined the same, as *(a+i) and *(b+i), where the
> addition is pointer arithmetic.
True, but &a and &b are very different, and "a" can be used as
an lvalue and "b" can not. "a" is a variable, and "b" is a
literal constant (that can, for static storage classes, be
resolved to a value at compile/load time).
> Function definitions can only define parameters as pointers
> (and lots else), not arrays. So passing either a or b passes
> the address it represents. (Function names also represent
> addresses in expressions, whereas, I believe, in C99 at least,
> struct names represent the struc, not its address.)
More information about the Python-list