Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: utzoo!watmath!clyde!burl!ulysses!ucbvax!decvax!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.lang.c Subject: Re: (int *)(char *)expr Message-ID: <2863@sun.uucp> Date: Wed, 9-Oct-85 04:36:50 EDT Article-I.D.: sun.2863 Posted: Wed Oct 9 04:36:50 1985 Date-Received: Sat, 12-Oct-85 17:40:19 EDT References: <118@mit-hector.UUCP> <2792@sun.uucp> <693@sfmag.UUCP> <268@ccivax.UUCP> <2855@sun.uucp> <208@rtp47.UUCP> Organization: Sun Microsystems, Inc. Lines: 36 > > All versions of "lint" that I know of complain when you say something like > > > > (int *)(char *)0; > > My handy-dandy vanilla-flavored SysV lint blesses expressions like > these, for example: "lint" will complain about a possible pointer alignment problem, at least. > But-but-but... "casting a pointer of one type to a pointer of another > type" is "in general, dangerous"? Code which so casts pointers runs the risk of circumventing the type system of C; as such, there's no guaranteeing *what* it does. It should be possible to do so - I believe even Ada has unchecked conversions to do so - but it should not be easy to do so. I think getting a warning, unless the conversion is to or from "void *", is sufficient. In pre-X3J11 C compilers - meaning most if not all present C compilers - there is no "void *", so allowing a cast to override the warnings you get from PCC about illegal pointer combinations is somewhat excusable. (But if casts are treated as ways of telling the compiler "trust me, I know what I'm doing", why does int i; long l; i = (int)(l % 2); still produce "long assignment may lose accuracy" messages? This renders the "-a" flag less useful, since there's no way to selectively turn off that particular check only in particular (sub-)expressions. One of the major reasons why people refuse to use "lint" is that there is a popular conception that it natters at you about non-problems coupled with the belief that the real problems it *will* find for you aren't major enough to justify the aggravation.) Guy Harris