2 lint questions
Jonathan A. Chandross
jac at paul.rutgers.edu
Thu Aug 17 07:04:01 AEST 1989
boyd at ingr.com (Boyd Nation) writes:
>1) How does one prevent lint from issuing a warning message about possible
>pointer alignment problems given the following line of code:
> x = (blivet *)malloc(sizeof(blivet));
jeffrey at algor2.uu.net (Jeffrey Kegler)
> #ifdef lint
> #define NOSTRICT(type, exp) ((exp)?(type)0:(type)0)
> #else
> #define NOSTRICT(type, exp) ((type)(exp))
> #endif
> so that the expression above becomes
> x = NOSTRICT(blivet *,malloc(sizeof(blivet)));
I use an entirely different approach. I declare a fake malloc:
void *my_malloc(size)
unsigned int size;
{
extern char *malloc();
return((void *)malloc(size));
}
and then whenever I use it I say something like:
....
extern void *my_malloc()
ZAP *zap_pntr = (ZAP *)my_malloc((U_INT)sizeof(ZAP));
This shuts up lint except for the line in my_malloc where I cast from
char * to void *. I figure that 1 ignorable complaint is better than
hundreds of them.
Jonathan A. Chandross
Internet: jac at paul.rutgers.edu
UUCP: rutgers!paul.rutgers.edu!jac
More information about the Comp.lang.c
mailing list