Array of pointers (in general)

Chris Torek chris at mimsy.umd.edu
Wed Dec 6 03:08:51 AEST 1989


In article <10468 at attctc.Dallas.TX.US> bobc at attctc.Dallas.TX.US
(Bob Calbridge) asks about having pointers that point to objects
that do not have names:

>My immediate need requires that I simply establish an array of pointers and
>also declare the space to which the pointers point.  The data area does not
>need to have an initial content but must be reserved.  Is this possible ...

The answer is `no and yes'.

C has only two kinds of unnamed objects, and only one of them is
available at compile time.  The construct

	"abc"

produces (in all but one special case) an unnamed object of type
`array N of char' (here N = 4), and evaluates to a pointer to the
first character of that array.  The other kind of unnamed object
is that returned by malloc().  All other C objects (but not necessarily
values) have names.

Someone else has already supplied the `yes' part of the answer, in
which you declare a single named object of type array N of T, and
then set your N pointer-to-T objects to point to each of these objects
in turn.
-- 
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