hiding lint's ravings (was Re: FAQ - malloc array - clarify)

Rich Salz rsalz at bbn.com
Wed Sep 12 04:11:47 AEST 1990


In <8086 at helios.TAMU.EDU> jdm5548 at diamond.tamu.edu (James Darrell McCauley) writes:
[ Summary:
    extern char *malloc();
    double **dpp = (double **)malloc((unsigned int)n * sizeof (double*));
 causes lint to complain "possible pointer alignment problem". ]

Some people said ignore it, but James replied:
>Well, I can just ignore warnings like this, but those who review
>my code (professors, employers, clients) are not likely to.
Then, simply put, they are not competent to review your code.

If you need a better solution, you can often fool lint by writing your own
malloc function that returns something with worst-case alignment.  For example:
	#define NEW(type, count)	xmalloc(count * sizeof (type))
	typedef double *ALIGN;

	ALIGN
	xmalloc(i) int i; {
	    ALIGN p = (ALIGN)malloc((unsigned int)i);
	    if (p == NULL) FatalError("no memory");
	    return p;
	}

	double **dpp = NEW(double*, n);
-- 
Please send comp.sources.unix-related mail to rsalz at uunet.uu.net.
Use a domain-based address or give alternate paths, or you may lose out.



More information about the Comp.unix.programmer mailing list