Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!hplabs!ucbvax!ucsfcgl!arnold From: arnold@ucsfcgl.UUCP (Ken Arnold%CGL) Newsgroups: net.lang.c Subject: Re: void * Message-ID: <9831@ucsfcgl.UUCP> Date: Thu, 24-Apr-86 14:36:56 EST Article-I.D.: ucsfcgl.9831 Posted: Thu Apr 24 14:36:56 1986 Date-Received: Sat, 26-Apr-86 06:16:38 EST References: <1883@ucsfcgl.UUCP> <728@bentley.UUCP> Reply-To: arnold@ucsfcgl.UUCP (Ken Arnold) Organization: UCSF Computer Graphics Lab Lines: 35 In article <728@bentley.UUCP> kwh@bentley.UUCP (KW Heuer) writes: >In article <1883@ucsfcgl.UUCP> ucsfcgl!arnold (Ken Arnold%CGL) writes: >>Purists will note that I really should say >> ptr = (some_type *) malloc(10 * sizeof *ptr); >>But eventually malloc() will be of type "void *". > >Okay, enlighten me. When I first saw the idea of "void *" I thought it was >to be a name for the most restrictive pointer type ("ALIGN *" for those who >know the malloc source). Then when I rechecked, I found that it was a new >name for the least restrictive pointer type, "char *". Now you seem to say >that the cast operator is unnecessary in your example. I'd like some more >detail about this beast. Specifically, suppose we have the following: > void *v; > char *c; > short *h; > ALIGN *a; >Of the 12 nontrivial assignment statements, which ones will ANSI C accept >without a cast? What will lint accept (with/without cast)? Well, as *I* understand it (and my draft is, of course, out of date), (void *) can be cast to any other pointer type without complaint. So ptr = malloc( ... ); would be as legal as int_var = float_var; i.e., the conversion would be automatic and silent (because it is guaranteed to work properly). Presumably, any other pointer assignment would generate a warning unless accompained by a cast (and I sure hope it is silent if I explicitly cast it). Ken Arnold