lint on malloc calls

brian at bradley.UUCP brian at bradley.UUCP
Sun Sep 11 09:43:00 AEST 1988


> /* Written  3:12 pm  Sep  8, 1988 by jgb at linus.UUCP */

	[ edited for brevity ]

> 
> 	entry *nextentry;
> 
> 	nextentry = (entry *) malloc(sizeof(entry));
> 
> Running lint -bach yields:
> 
> 	phone.c(61): warning: illegal pointer combination
> 	phone.c(61): warning: possible pointer alignment problem
> 
> What am I doing wrong?  Doesn't K+R suggest this on pp. 133-134 (at
> the end of section 6.5)?

  You probably didn't tell lint or cc what malloc() returns, so it
assumed int malloc()... The warning is given because you have done
an explicit cast of a pointer to an integer. Just add the following
line to either the top of your program or the top of your function:

extern char *malloc();

  Or, if you compiler supports void*

extern void *malloc();

...............................................................................

  When the going gets weird, the weird turn pro.

  Brian Michael Wendt       UUCP: {cepu,ihnp4,uiucdcs,noao}!bradley!brian
  Bradley University        ARPA: cepu!bradley!brian at seas.ucla.edu
  (309) 677-2230            ICBM: 40 40' N  89 34' W



More information about the Comp.lang.c mailing list