Casting for a fish that never arrived

Chris Torek chris at umcp-cs.UUCP
Tue May 14 10:00:46 AEST 1985


Your second example works because Words is (correctly) a pointer to
an array 4 of pointer to char (in cdecl syntax).  You don't even need
the casts in the assignment statements.

If you want to do it without typedefs, try

char *Cwords[2][4] = {{"1", "2", "3", "4"}, {"a", "b", "c", "d"}};
char *Pwords[2][4] = {{"w", "x", "y", "z"}, {"9", "8", "7", "6"}};
char *(*Words)[4];

main()
{
	register int i, j;

	Words = Cwords;
	for (i = 0; i < 2; i++)
		for (j = 0; j < 4; j++)
			printf("%s\n", Words[i][j]);
	Words = Pwords;
	for (i = 0; i < 2; i++)
		for (j = 0; j < 4; j++)
			printf("%s\n", Words[i][j]);
}
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.lang.c mailing list