Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!linus!decvax!ucbvax!ucdavis!lll-crg!gymble!umcp-cs!seismo!brl-tgr!tgr!cottrell@NBS-VMS.ARPA From: cottrell@NBS-VMS.ARPA (COTTRELL, JAMES) Newsgroups: net.lang.c Subject: Casting Pointers Message-ID: <2030@brl-tgr.ARPA> Date: Wed, 9-Oct-85 21:13:07 EDT Article-I.D.: brl-tgr.2030 Posted: Wed Oct 9 21:13:07 1985 Date-Received: Sat, 12-Oct-85 07:57:24 EDT Sender: news@brl-tgr.ARPA Lines: 45 /* > Ah yes. Casting pointers. A favorite passtime for anyone ... I myself would rather cast aspersions, spells, or plays. > who uses an architecture where char * has different format from int * I don't know. Who does? Maybe someday they'll get a *real* computer. > > All versions of "lint" that I know of complain when you say something like > > > > (int *)(char *)0; Hey, what we need is a `(lint *)' type! This will cast any expression to a type that neither lint nor some guys will complain about. > > since you're casting a pointer of one type to a pointer of another type > > which is, in general, dangerous. So is an architexure where all pointers are not the same size as ints. Even if I were to kneel at the sacred alter of portability, there are all those other jokers out there that don't know the difference. I propose passing all parameters on the stack as H-Format Floating Point (that's VAXish for all you heathens out there), a one size fits all approach. (add an entire line of :-)'s to this paragraph except for the first line.) > But-but-but... "casting a pointer of one type to a pointer of another > type" is "in general, dangerous"? You mean that constructs like > > foo_ptr = (foo_type *)malloc( sizeof( foo_type ) ); > > are "in general, dangerous"? Say it ain't so! Not fair. This is a *specific* example. Malloc is special. > I'm not quite sure what Guy was asserting above, but I suspect that it > all boils down to ... ... is RTFM. How many times do we have to have this discussion? Guy, maybe you should write a book & make some real money on this stuff. I'll even buy a copy of it myself. jim cottrell@nbs */ ------