Topic: void\* vs const void\*
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Thu, 5 Jan 1995 10:33:25 GMT Raw View
pjm3@ns2.CC.Lehigh.EDU (PAUL JASON MARTINO) writes:
>I am getting some strange results running the following code on Borland 4.5.
>
>void f( void * );
>void f( const void * );
>
>void main()
main() should return an `int'.
> {
> char *c;
>
> f( c ); // does not issue an error
> f( (char *) 0 ); // error: ambiguous
> }
>
>I can find nothing in the standard doc that should make the f(c) call be
>non-ambiguous. Borland 3.1 flags f(c) as an error. Our product PC-Lint for
>C/C++ flags both of them as an error. I was curious is anyone knows who is
>correct.
Neither PC-Lint nor Borland 3.1 is correct, IMHO - both statements
should be unambiguous, and should invoked `f(void *)'.
But Borland's behaviour seems particularly strange, since there
shouldn't be any difference between `c' and `(char *)0' in this case.
I base my conclusion on the Sept working draft.
The conversion sequences involved in this case are
S1: (char *) -> (void *)
and
S2: (char *) -> (void *) -> (const void *)
Now 13.2.3.2/3 states:
Standard conversion sequence S1 is a better conversion sequence
than standard conversion sequence S2 if
- S1 is a proper subsequence of S2, or ...
Hence S1 is a better conversion sequence than S2, and so there is
no ambiguity - the code should invoke `f(void *)'.
P.S. Followups redirected to comp.std.c++.
--
Fergus Henderson - fjh@munta.cs.mu.oz.au