Xref: utzoo comp.lang.c++:13286 comp.std.c++:892 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++,comp.std.c++ Subject: Re: Default type of "0" Message-ID: <713@taumet.com> Date: 7 May 91 15:18:08 GMT References: <74609@brunix.UUCP> Followup-To: comp.lang.c++ Organization: Taumetric Corporation, San Diego Lines: 25 sdm@cs.brown.edu (Scott Meyers) writes: >What is the type of the constant "0", independent of any context? A literal zero has type int. It can also serve as a null pointer constant when initializing a pointer. int i = 0; // 0 has type int double d = 0; // 0 implicitly converted to type double T* t = 0; // 0 implicitly converted to type T* T* u = i; // illegal, since i is not a null pointer constant >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*? This is not ambiguous. The zero is an exact match to f(int), but requires a conversion to f(char*). If your compiler calls it ambiguous, this is a bug. -- Steve Clamage, TauMetric Corp, steve@taumet.com