Xref: utzoo comp.lang.c:30540 comp.os.msdos.programmer:247 alt.msdos.programmer:1959 Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!samsung!noose.ecn.purdue.edu!iuvax!purdue!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c,comp.os.msdos.programmer,alt.msdos.programmer Subject: Re: Suspicious pointer conversion warning in Turbo C 2.0 Message-ID: <25725@mimsy.umd.edu> Date: 26 Jul 90 06:04:03 GMT References: <1990Jul25.230836.2442@Octopus.COM> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 61 In article <1990Jul25.230836.2442@Octopus.COM> stever@Octopus.COM (Steve Resnick) writes: >As far as I know, when I provide a prototype for a function which accepts >a void pointer, the compiler should not bitch about type conversions between >pointers. The code fragment below generates a warning message .... The ANSI standard only says when diagnostics are required; it makes no prohibitions about extra diagnostics. In other words, compilers are free to warn about anything they like (`foo.c, line 354: warning: code written at 4 AM'). Of course, some warnings are rather less useful than others (although the above might well be particularly good, actually). >The parameter bitched about is the second pointer. >The first pointer in both cases is not complained about. [everything but the relevant bits trimmed:] >void AddLNode(void ** Hptr, void * Nptr); > Tlist *Head, *Walker; > AddLNode(&Head,Walker); /* This statement generates a warning */ Now this is exactly backwards: a good compiler should complain about the first parameter, not the second. Argument passing is semantically equivalent to assignment, so the commented line is rather like writing: void **Hptr; void *Nptr; Hptr = &Head; Nptr = Walker; The first assignment expands to = &; which becomes = ; which is an attempt to stuff a `Tlist **' into a `void **'. The C standard guarantees that any pointer type (e.g., Tlist **) must fit into a `void *'; it makes no such guarantee about a `void **'. In other words, this need not work, and the compiler ought to complain. The second assignment expands to = &; which becomes = ; which (because Tlist** fits in void*) has to `work' (the compiler is free to complain, but this should at least be an option, or customers will turn away in droves). -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@cs.umd.edu Path: uunet!mimsy!chris