Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!nosc!ucsd!ucsdhub!hp-sdd!hplabs!hpda!hpcuhb!hpcllla!hpclisp!hpclscu!shankar From: shankar@hpclscu.HP.COM (Shankar Unni) Newsgroups: comp.lang.c Subject: Re: lint on malloc calls Message-ID: <660017@hpclscu.HP.COM> Date: 9 Sep 88 17:33:26 GMT References: <39617@linus.UUCP> Organization: HP NSG/ISD California Language Lab Lines: 34 > > nextentry = (entry *) malloc(sizeof(entry)); > >Running lint -bach yields: > > phone.c(61): warning: illegal pointer combination > phone.c(61): warning: possible pointer alignment problem Well, one can sort of understand lint's point of view (assuming a low-IQ lint): Malloc returns a "char *" (presumably that's how you declared it) a "char *" can *THEORETICALLY* point to the middle of a word (even though we know that malloc always returns appropriately aligned pointers) ergo, casting it to a struct pointer could *THEORETICALLY* cause an alignment problem (if the struct has an alignment >= 1 word) (The illegal combination message is just plain dumb...) A possible workaround to pacify your lint: Declare malloc as double *malloc(); -- Shankar. P.S. I don't know what this would do on machines in which char *'s and double *'s have different representations and in which malloc actually returns a char * aligned to a double boundary (believe me, I know such a machine). But if your machine doesn't have a terminal case of pointer- representation-itis, the above should work...