Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!ucsd!sdcsvax!ucsdhub!hp-sdd!hplabs!hpda!hpcupt1!hpcuhb!hpcllla!hpcllz2!walter From: walter@hpcllz2.HP.COM (Walter Murray) Newsgroups: comp.lang.c Subject: Re: Help me cast this! Message-ID: <7330002@hpcllz2.HP.COM> Date: 4 May 88 16:04:42 GMT References: <294@fedeva.UUCP> Organization: HP NSG/ISD Computer Language Lab Lines: 42 Bill Daniels writes: > How do I cast the malloc() in the following program to avoid > the lint cries of "warning: illegal pointer combination" et al? [program abbreviated] > #include > main() > { > char *malloc(); > struct outfile { > int j; > int k; > } (*output)[]; > output = malloc(sizeof(struct outfile) * 3); > } > THIS IS MY LINT'S OUTPUT: > trial.c > ============== > warning: illegal pointer combination > (12) > warning: possible pointer alignment problem > (12) To avoid the "illegal pointer combination", try: output = (struct outfile (*)[])malloc(sizeof(struct outfile) * 3); The "possible pointer alignment problem" warning comes from the fact that malloc(3) is declared to return char*, even though we know that the alignment of its return pointer is such that it can be used for anything. To get rid of that warning, try: output = (struct outfile (*)[])(int)malloc(sizeof(struct outfile) * 3); Conversions of pointers to integral types and back are implementation- defined, but this should work if int on your machine is wide enough to hold a pointer. If not, try long instead. --Walter Murray