* Alan W. Irwin <irwin@...> [2005-03-10 12:28]:
> On 2005-03-10 18:52+0100 Rafael Laboissiere wrote:
> >* Alan W. Irwin <irwin@...> [2005-03-10 08:22]:
> >>If you look that up, the line in question is
> >> difilt(&clipx, &clipy, 4, &clxmin, &clxmax, &clymin, &clymax);
> >>Since clipx and clipy are already typed as arrays, shouldn't the first two
> >>arguments be changed to clipx, clipy?
> >Yes, the two first "&" are probably typos. You can remove them.
> You imply that whether they are there or not doesn't matter except for the
> warning message. Perhaps it is off-topic, but I would like to learn a bit
> more about C pointers so can anybody tell me why it doesn't matter?
Welcome to the world of C programming. Confusion between pointers and
arrays is one of the most common misunderstandings of the language. Let
me try to help you.
difilt is declared as:
difilt (PLINT *cx, ...
Note that the first argument of difilt is a pointer-to-a-PLINT (PLINT*).
clipx is declared in the following way:
This means that clipx is an array. Notice that clipx is not a pointer, by
no means. Think of cplix as an object, like int or float, which has a
definite size. You are perfectly allowed to take the address of clipx
with the & operator, in the same way that you take the address of a
variable declared as, say:
Taking the address of the clipx array results in a type
"pointer-to-an-array-of-four-PLINTs". Were the difilt function defined
difilt (PLINT (*cx), ...
then passing &clipx as argument would work without compilation warning,
because the types match.
Now you would ask me: "Nice, buddy, but why it works when I remove the
ampersand?" Here is the answer: when the compiler sees clipx alone (i.e.
without the subsequent brackets), it understands that you want the
address of the variable and automatically casts it with to the type
PLINT*. Notice that all unidimensional arrays of PLINT when referenced
by their name (without the brackets) have the same type: PLINT*.
Hope this helps.