Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Help me cast this! Message-ID: <11328@mimsy.UUCP> Date: 3 May 88 14:43:17 GMT References: <294@fedeva.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 28 Keywords: pointer to array of struct In article <294@fedeva.UUCP> wrd3156@fedeva.UUCP (Bill Daniels) writes: > char *malloc(); > struct outfile { > int j; > int k; > } (*output)[]; > output = malloc(sizeof(struct outfile) * 3); First, note that output is not a proper variable: % echo 'declare output as pointer to array of struct outfile' | cdecl Warning: Unsupported in C -- Pointer to array of unspecified dimension struct outfile (*output)[] % In particular, your compiler will let you write (*output)[i], or output[0][i], but try output[j][i] and ! I have argued this point here before; I will only say now that this is not what C wants you to say to create a dynamic array 3 of struct outfile: you should be using a simple pointer. Nonetheless, it happens to work. On to the cast: The syntax of a cast is exactly the same as the syntax of a declaration, minus the variable name. Hence to cast malloc to the same (unsupported) type: output = (struct outfile (*)[])malloc(...); -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris