Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!nrl-cmf!ukma!husc6!bbn!bbn.com!rsalz From: rsalz@bbn.com (Rich Salz) Newsgroups: comp.lang.c Subject: Re: lint on malloc calls Message-ID: <1040@fig.bbn.com> Date: 12 Sep 88 14:08:33 GMT References: <39617@linus.UUCP> <9900007@bradley> <5427@csli.STANFORD.EDU> Organization: BBN Systems and Technologies, Inc. Lines: 43 Juergen "Gandalf" Wagner, , asks how you can make lint happy if one program has the following three lines: cp = (char *) malloc(10*sizeof(char)); sp = (short *) malloc(10*sizeof(short)); dp = (double *) malloc(10*sizeof(double)); He suggests this: #ifdef lint extern char *malloc_char(); extern short *malloc_short(); extern double *malloc_double(); #else /* !lint */ # define malloc_char malloc # define malloc_short malloc # define malloc_double malloc #endif /* lint */ On the systems I use, which are mostly BSD derivatives, lint will keep quiet if it sees you casting a "worst-case" pointer into something not so bad. I you write your own wrapper around malloc (which is usually a good idea anyway), you can get the lint natterings down to one line. In system_header.h typedef int WORST_CASE; extern WORST_CASE *Mallocator(); in alloc.c #include "system_header.h" WORST_CASE * Mallocator(count) int count; { char *malloc(); WORST_CASE p; if (p = (WORST_CASE *)malloc(count)) return(p); YelpAndDie(); } I remember this trick also working on Version7 lints. It's been a long time since I've used SysV- -- Please send comp.sources.unix-related mail to rsalz@uunet.uu.net.