Path: utzoo!utgpu!jarvis.csri.toronto.edu!dgp.toronto.edu!flaps Newsgroups: comp.lang.c From: flaps@dgp.toronto.edu (Alan J Rosenthal) Subject: Re: Pointer/array compatibility Message-ID: <1989Sep28.205805.9786@jarvis.csri.toronto.edu> References: <4959@uhccux.uhcc.hawaii.edu> Distribution: na Date: 29 Sep 89 00:58:05 GMT cs211s14@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