Path: utzoo!attcan!uunet!mcvax!unido!iaoobelix!woerz From: woerz@iaoobelix.UUCP (Dieter Woerz) Newsgroups: comp.lang.c Subject: Re: lint on malloc calls Summary: lint is simply warning you Keywords: lint, malloc, alignment Message-ID: <216@iaoobelix.UUCP> Date: 13 Sep 88 22:51:18 GMT References: <39617@linus.UUCP> <9900007@bradley> Reply-To: woerz@iaoobelix.UUCP (Dieter Woerz) Organization: Fraunhofer Institut fuer Arbeitswirtschaft und Organisation Lines: 62 In article <9900007@bradley> brian@bradley.UUCP writes: > >> /* Written 3:12 pm Sep 8, 1988 by jgb@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: This isn't the cause here, because, if you don't tell lint, that malloc returns a char *, lint will complain with a message: warning: illegal combination for pointer and integer, op = The cause is, that jgb@linus.UUCP asked lint with the a flag to (I cite the lint manual on Ultrix V2.2, the one I've handy) Complain about casts which have questionable portability. The problem is, that lint doesn't know, that malloc always returns a best aligned pointer instead of (as char * normally can) a possibly worst aligned one. This would be of "questionable portability" for other systems. >extern char *malloc(); > > Or, if you compiler supports void* > >extern void *malloc(); This would only help, if you lint library, where malloc is defined, is changed too for malloc returning void *. But I think lint must be changed for this one too, as lint must know that a void * will always be aligned properly. I'm not sure, if the current lint's know this definition. ------------------------------------------------------------------------------ Dieter Woerz Fraunhofer Institut fuer Arbeitswirtschaft und Organisation Abt. 453 Holzgartenstrasse 17 D-7000 Stuttgart 1 W-Germany BITNET: iaoobel.uucp!woerz@unido.bitnet UUCP: ...{uunet!unido, pyramid}!iaoobel!woerz