char ** (was Malloc in Turbo C)

Chris Torek chris at mimsy.umd.edu
Wed Mar 7 19:32:29 AEST 1990


In article <90058.153755CMH117 at psuvm.psu.edu> CMH117 at psuvm.psu.edu
(Charles Hannum) writes:
>>       char **head, **cp;
>        ~~~~~~~  A "char **" is a "pointer to a char *" (or, to make Chris
>                 Torek cringe, a "pointer to an array??(SIZE_UNKNOWN??) of
>                 char *'s)  (Note:  Excuse the ASCII tryglyphs; I'm using an
>                                    IBM 3179G terminal right now.)

You were right the first time: `char **head' declares head as a pointer
to a pointer to char.  This pointer can point to zero or more contiguous
objects, each of which is a `char *'---a pointer to char---and each of
which can in turn point to zero or more contiguous objects, each of which
is a char.

Others (including Charles Hannum, for once) have produced correct
explanations as to why the code in `>>' above was incorrect.  I merely
felt it necessary to point out that `char **' is not the same as
`char (*)[]'.  They must not be interchanged, and the latter should almost
never be used---among other things, it is never any more useful than
`char *'.  (A pointer that points to zero or more arrays of unknown
size, as this one does, can only be used to access the first of those
zero or more arrays, because the second, third, fourth, etc., such arrays
are located some unknown distance away from the first.  The first is
at a known distance only because it is always zero bytes away from itself.)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list