Double inderection question

Hal Pomeranz pomeranz at cs.swarthmore.edu
Wed Aug 3 03:23:37 AEST 1988


Consider the following:

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'.  I've also
tried '&&array[0]', '&&(array[0])', '&(&array[0])', etc. and none of these
has worked.  From my limited understanding 'array' is a pointer to the first
element (i.e. a pointer to array[0]), so &array should be a pointer to the
pointer.  It is possible that I'm inferring too much from K&R, but this seems
like a reasonable extension of the rules they lay down.  So my question is:
where does the fault lie?  With my understanding?  With the C compiler?  Or
(*gasp*) with K&R for not making consistant rules?  As a side point, the 
following does work:

char array[10], **ptr, *bogus_ptr;

main()
{ 
   bogus_ptr = array;
   ptr = &bogus_ptr;
   .
   .
   .
}

It strikes me that if I can do what I want in this roundabout way, I should
also be able to do it directly.

Hal Pomeranz
-- 
______________________________________________________________________________
|UUCP: ...!rutgers!bpa!swatsun!pomeranz          | Living on a lighted stage
|CS Net: pomeranz at cs.swarthmore.edu              |    approaches the unreal...
|BitNet: vu-vlsi!swatsun!pomeranz at psuvax1.bitnet |                  -Rush



More information about the Comp.lang.c mailing list