Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site oliveb.UUCP Path: utzoo!watmath!clyde!floyd!harpo!seismo!hao!hplabs!oliveb!jerry From: jerry@oliveb.UUCP (Jerry Aguirre) Newsgroups: net.unix-wizards Subject: Re: casts Message-ID: <318@oliveb.UUCP> Date: Thu, 5-Apr-84 15:23:01 EST Article-I.D.: oliveb.318 Posted: Thu Apr 5 15:23:01 1984 Date-Received: Sat, 7-Apr-84 05:56:54 EST References: <233@sri-arpa.UUCP> Organization: Olivetti ATC, Cupertino, Ca Lines: 22 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