lint on malloc calls
Shankar Unni
shankar at hpclscu.HP.COM
Sat Sep 10 03:33:26 AEST 1988
>
> 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...
More information about the Comp.lang.c
mailing list