Discarded Function Values (To Cast or Not to Cast)
T. William Wells
bill at twwells.com
Wed Nov 22 20:27:19 AEST 1989
In article <11161 at riks.csl.sony.co.jp> diamond at ws.sony.junet (Norman Diamond) writes:
: What DO you do about calls to malloc?
Something like:
extern void *real_alloc();
#ifdef lint
static void fake_alloc(n) unsigned n; { (void)real_alloc(n); }
#define myalloc(x) (fake_alloc(x), 0)
#else
#define myalloc(x) real_alloc(x)
#endif
When lint is not defined, myalloc just goes to real_alloc, which
does things like checking for out of memory after the call to
malloc.
When lint is defined, myalloc has the call to fake_alloc in order
to type check its argument, and the zero is what the cast that
goes with the myalloc sees. Lint doesn't mind casting the zero,
so there are no complaints.
---
Bill { uunet | novavax | ankh | sunvice } !twwells!bill
bill at twwells.com
More information about the Comp.lang.c
mailing list