Array of pointers (in general)

Conor P. Cahill cpcahil at virtech.uucp
Mon Dec 4 15:06:22 AEST 1989


In article <10468 at attctc.Dallas.TX.US>, bobc at attctc.Dallas.TX.US (Bob Calbridge) writes:
> Example:  I want 10 uninitialized structures defined but I want to reference
> them through an array of pointers.  Rather than give each structure a name
> and declare the array like
> 
> struct entry *list [] = {
> 	&S1, &S2, &S3, &S4
> };
> 
> can I avoid having to declare the structures S1, S2, etc. elsewhere in the
> program?

You could just do a

	struct entry list[10]; 

and not use pointers at all.  Or, if you really need to use pointers you
could do:

	#define CNT 10

	struct entry *list[CNT];
	struct entry  reallist[CNT];

and somewhere in the begining of your program do:

	for(i=0; i < CNT; i++) list[i] = reallist+i;


-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.lang.c mailing list