Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!cwjcc!hal!nic.MR.NET!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Do you have to cast void pointers when dereferencing them? Keywords: (With ANSI C) Message-ID: <15047@mimsy.UUCP> Date: 17 Dec 88 16:26:11 GMT References: <2414@ssc-vax.UUCP> <15012@mimsy.UUCP> <3050@arcturus> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 43 In article <3050@arcturus> evil@arcturus.UUCP (Wade Guthrie) writes: >but this seems to indicate that the dpANS performs implicit type >conversions for pointers. dpANS C does, but only for pointer to T => pointer to void and pointer to void => pointer to T where T is any type other than `pointer to void' (for which conversion is unnecesssary) and perhaps `pointer to function returning T1'. (It is not entirely clear to me that the hack we used to allow char *pc; void *pv; pc = pv; pv = pc; in 4BSD PCC is wrong, but it does also allow void *pv; int (*pfi)(); pv = pfi; pfi = pv; and I am suspicious that this *is* wrong.) >To say that pointer_of_one_type = pointer_of_another_type is legal, the >code must know the type of the lvalue to put the rvalue into the proper >representation. Is this not true? It is true. But the compiler does indeed know both types. In the dpANS, if at least one of those types is `pointer to void' (and the other provisos above hold true) the assignment is legal; otherwise, such an assigment is legal only if the assignment is the result of a cast: (pointer_of_one_type) pointer_of_another_type, e.g., int i; (short *)&i (remember that a cast is equivalent to assignment to an unnamed temporary variable---I like to consider `assignment' to include all casts). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris