Dumb question on dyn. mem. alloc (if(hate(novices)) dont_read();)

Chris Torek chris at umcp-cs.UUCP
Sat Jul 20 17:08:58 AEST 1985


Lint doesn't realize that malloc and calloc have been written such
that that "possible pointer alignment problem" never occurs.  The
thing to do is ignore the message (or teach lint how to say that
a function returns a ``very aligned'' pointer; someone once suggested
using /*ALIGNOK*/ similar to the way /*NOTREACHED*/ and /*ARGSUSED*/
tell lint not to complain).

Another alternative is to use code like this:

	struct foo *
	getfoo()
	{
		struct foo *p;

	#ifdef lint
		p = NULL;
	#else
		p = (struct foo *)malloc((unsigned)sizeof (struct foo));
		if (p == NULL)
			error(1, errno, "out of memory in getfoo");
		p->this = p->that = theotherthing;
	#endif
		return (p);
	}

since lint knows that ``p = 0'' is not assigning an unaligned pointer
to p.  Of course this loses the type checking in the rest of the
code.  (Sigh.)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.lang.c mailing list