Help me cast this!

Richard A. O'Keefe ok at quintus.UUCP
Sat May 7 13:40:20 AEST 1988


In article <691 at acf3.NYU.EDU>, pedersen at 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.



More information about the Comp.lang.c mailing list