casts

Jerry Aguirre jerry at oliveb.UUCP
Fri Apr 6 06:23:01 AEST 1984


One problem, from lint's point of view, with:

	p = (struct foo *)malloc(size);

is that when casting a char pointer into a pointer to a larger size
opject there is no guarantee that the pointer is aligned.  A char
pointer can be odd while most machines require an even pointer for
ints and larger types.  Of course malloc is guaranteed to return
a pointer which has worst case alignment.  The problem is that lint
does not know this.  The manual calls these "questionable" casts.
Not wrong, just not guaranteed right.

I fooled around with this while working to make a program squeaky
clean.  I finally wrote a small procedure to do the malloc and
cast, returning a pointer of the type I needed.  This reduced
the lint errors to just 1 place.  I had no luck getting our version
of lint to shut off type checking for that procedure.  The NOSTRICT
option did not work (a strings on lint shows it doesn't even have
that option).

					    Jerry Aguirre
    {hplabs|fortune|ios|tolerant|allegra|tymix}!oliveb!jerry



More information about the Comp.unix.wizards mailing list