Path: utzoo!utgpu!water!watmath!clyde!bellcore!faline!thumper!ulysses!andante!alice!ark From: ark@alice.UUCP Newsgroups: comp.lang.c Subject: Re: Double inderection question Keywords: is this messed up or am I? Message-ID: <8082@alice.UUCP> Date: 3 Aug 88 11:59:48 GMT References: <2001@tulum.cs.swarthmore.edu> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 46 In article <2001@tulum.cs.swarthmore.edu>, pomeranz@swatsun.UUCP writes: > char array[10], **ptr; > main() > { > ptr = &array; > . > . > . > } > > Now, when I try and compile this program with our C compiler (Sun OS 4.0), I > get something like 'warning: & before array or function: ignored'. Many C compilers treat `array' as equivalent to `&array[0]' in this context. Strictly speaking, a compiler that does this ought to be entitled to treat `&array' as `&(&array[0])', which is illegal as (the inner) & does not yield an lvalue. However, the compiler figures that when you said &array you mean &array[0], so it quietly translates it for you. In any event, such a compiler treats &array as a char * and not as a char **, so the assignment should elicit an error message. This all changes in ANSI C. There, &array is actually a pointer to the array! Its type is `pointer to array of 10 characters' and it might be used this way: char array[10]; char (*p)[10]; p = &array; I have it on good authority that this is valid ANSI C, and indeed other C compilers I've tried will accept all but the last line. The real question is: what do you want? You sound like you want ptr to point to another pointer, which in turn points to the initial element of the array. If so, the only way to do it is to declare the intermediate pointer explicitly: C is not in the habit of manufacturing temporary lvalues. Incidentally, my book `C Traps and Pitfalls' discusses the relationship between arrays and pointers in some detail.