Xref: utzoo comp.lang.c++:13265 comp.std.c++:890 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!brunix!sdm From: sdm@cs.brown.edu (Scott Meyers) Newsgroups: comp.lang.c++,comp.std.c++ Subject: Default type of "0" Message-ID: <74609@brunix.UUCP> Date: 6 May 91 15:34:17 GMT Sender: news@brunix.UUCP Reply-To: sdm@cs.brown.edu (Scott Meyers) Organization: Brown University Department of Computer Science Lines: 39 What is the type of the constant "0", independent of any context? If there is such a default type, call it T. Then are there any conversions in any of the following? int i = 0; // conversion from T to int? int *ip = 0; // conversion from T to int*? double d = 0; // conversion from T to double? The reason for asking is that it would be nice to avoid the following ambiguity: void f(int x); // parameter of a numerical type void f(char *s); // parameter of a pointer type f(0); // ambiguous call -- is 0 an int or a char*? I would prefer that the default type for 0 be int, in accord with the default type of functions and consts. Then the call to f(0) would resolve to calling f(int) and there would be no ambiguity. It would of course still be possible to call f(char*) via an explicit cast or, more palatibly, by declaring a const null pointer of the appropriate type, e.g., const char *NULLSTRING = 0; f(NULLSTRING); Unfortunately, we'd have to augment the rules for disambiguating overloaded functions described in section 13.2 of the ARM (pp. 312ff of the American edition). There are currently five rules. I'd add the conversion of "0" to "null pointer" to rule 3, on standard conversions. I suspect the matter is substantially more complicated and subtle than I've described here. Comments? Scott ------------------------------------------------------------------------------- What do you say to a convicted felon in Providence? "Hello, Mr. Mayor."