Pointer/array compatibility

Alan J Rosenthal flaps at dgp.toronto.edu
Fri Sep 29 10:58:05 AEST 1989


cs211s14 at uhccux.uhcc.hawaii.edu (Julian Cowley) writes:
>int a[2][3][5], ***ippp, **ipp, *ip, i, j;
>
>i = a[0][0][0];		/* ok */
>ip = &a[0][0][0];	/* ok */
>
>ip = a[0][0];		/* why? */
>ipp = a[0];		/* why? */
>ippp = a;		/* why? */
>
>i = ipp[i][j];		/* why^2? */

>Why are the latter expressions legal?  For instance, I thought
>that a[0][0] is interpreted as pointer to array 5 of int and ip
>as a pointer to int, so they would be incompatible.

Well, the answer is that ipp = a[0] and ippp = a are not legal!  What compiler
are you using?  (rhetorical question)
PCC says (sunos 3.5):
	"test.c", line 9: warning: illegal pointer combination
	"test.c", line 10: warning: illegal pointer combination

However, ip = a[0][0] is fine.  a[0][0] is array 5 of int, not pointer to array
5 of int.

(I assume the reason you thought it odd that i = ipp[i][j] was legal is because
you thought that ipp = a[0] was legal.)

ajr



More information about the Comp.lang.c mailing list