Double inderection question

Rob Carriere rob at kaa.eng.ohio-state.edu
Wed Aug 3 13:37:25 AEST 1988


In article <2001 at tulum.cs.swarthmore.edu> pomeranz at cs.swarthmore.edu (Hal Pomeranz) writes:
>
>Consider the following:
>
>char array[10], **ptr;
>
> [ and now ptr cannot be assigned the value &array ]

This is as it is supposed to be.  Consider: the name of array *does*
(as you said) represent a pointer to the start of the array, but, and
this is the crucial fine print, NO STORAGE HAS BEEN ALLOCATED FOR THAT
POINTER!  It is a compiler constant.  One way to look at this is to
say that what you are doing is similar to:

int *foo = &1;

Which is also wrong (thank God!  One language called FORTRAN is quite
enough!).

Now in your second fragment, *you* create a space for this array
pointer to go, and then you *can* refer to it to your hearts content.
Carrying on my metaphor, this is similar to:

int  bar = 1;
int *foo = &bar;

Which will work too.

Summary: there was nothing *wrong* with the rules, they were just a
little ( :-) obscure.  

Rob Carriere



More information about the Comp.lang.c mailing list