Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: Help me cast this! Message-ID: <942@cresswell.quintus.UUCP> Date: 7 May 88 03:40:20 GMT References: <294@fedeva.UUCP> <7330002@hpcllz2.HP.COM> <691@acf3.NYU.EDU> Organization: Quintus Computer Systems, Mountain View, CA Lines: 34 Summary: shutting lint up about malloc In article <691@acf3.NYU.EDU>, pedersen@acf3.NYU.EDU (paul pedersen) writes: > Better just to eat the lint complaints automatically with grep -v, as someone > else has already suggested. There is a slightly better way still. #ifdef lint #define Malloc(Type,Amount) ((void)malloc(Amount), (Type)(0)) #else #define Malloc(Type,Amount) (Type)malloc(Amount) #endif #define Talloc(Type) Malloc(Type*,sizeof (Type)) typedef ..... Thing; Thing *p; p = Talloc(Thing); lint #defines lint, so lint will see p = ((void)malloc(sizeof (Thing)), (Thing*)(0)); but the C compiler will see p = (Thing*)malloc(sizeof (Thing)); This shuts lint up about _only_ pointer alignment problems involving malloc(), which is what you really want, as the others may be genuine. When you find other generic cases, you can fix them the same way. That's what #ifdef lint is for! Another common use for #ifdef lint is for things like #ifndef lint static char copyr[] = "@(#)Copyright (C) 1988 Muppet Labs, Incorporated."; #endif where lint would complain about copyr not being used.