why cannot assign to function call

Mark Wooding mdw at distorted.org.uk
Sun Jan 11 19:42:04 CET 2009


Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:

> I guess this is where you explain again that arrays in C are "bizarre", 
> and that while "int arr[2]" inside a function body means "declare an 
> array of two ints and call it 'arr'", the exact same declaration in a 
> function parameter list means something else. 

I quoted 6.7.5.3p7 before.  Please pay attention.

: A declaration of a parameter as ``array of type'' shall be adjusted to
: ``qualified pointer to type'', where the type qualifiers (if any) are
: those specified within the [ and ] of the array type derivation. If
: the keyword static also appears within the [and ] of the array type
: derivation, then for each call to the function, the value of the
: corresponding actual argument shall provide access to the first
: element of an array with at least as many elements as specified by the
: size expression.

> "Declare a pointer which points to an array of two ints, call the pointer 
> 'arr', and dereference the pointer every time it is used inside the 
> function as if you were referring to the array directly".

No.  Declare a pointer which points to an int, and call the pointer
`arr'.

> Am I close?

Vaguely.  A pointer to an array is not the same as a pointer to its
first element.  The former has type T (*)[N]; the latter has type T *.
The compiler entirely ignores the number (unless you write `static' --
little-known C99 feature).

There is no further magic: it's just a pointer.

-- [mdw]



More information about the Python-list mailing list