Pointers vs. arrays: another dumb question...

Tanner Andrews tanner at ki4pv.UUCP
Tue Jun 24 00:57:52 AEST 1986


) ncoast!allbery writes on the matter of casting a pointer to an
) array of pointers to a struct.

For the purposes of malloc casting, I would suggest neither of:
	(struct foo *)malloc( )
	(struct foo (*)[])malloc( )

Try instead the construct:
	(struct foo **)malloc( )

Consider that you are generating an array of pointers; what you are
getting back from malloc() is a pointer to this array.  Actually, it
points at the first pointer.

The same declaration would be appropriate for the variable, of
course:
struct foo
	**my_ptr;

-- 
<std dsclm, copies upon request>	   Tanner Andrews



More information about the Comp.lang.c mailing list