Xref: utzoo comp.lang.c++:13298 comp.std.c++:894 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!dkuug!diku!juul From: juul@diku.dk (Anders Juul Munch) Newsgroups: comp.lang.c++,comp.std.c++ Subject: Re: Default type of "0" Message-ID: <1991May7.162035.9247@odin.diku.dk> Date: 7 May 91 16:20:35 GMT References: <74609@brunix.UUCP> Sender: juul@skinfaxe.diku.dk Organization: Department of Computer Science, U of Copenhagen Lines: 40 sdm@cs.brown.edu (Scott Meyers) writes: >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*? [stuff deleted] Try: printf("%d,%d,%d\n", sizeof(int), sizeof(void*), sizeof(0)); on a system with different sizes for int and pointers. What you'll find is that "0" is foremost an integer (which incidentally may be used in place of a pointer :-). But I wonder, if we have #define NULL 0 (which is ANSI C compliant, I don't know if C++ is any different), then f(NULL) would call f(int)?! This seems highly unreasonable to me, and it looks like yet another good reason why the implicit conversion of 0 to the null pointer should be disallowed. Instead, NULL should be used whenever a null pointer is needed. NULL being defined as #define NULL ((void*)0) And int* ip = 0; would then be illegal, and replaced by int* ip = NULL; -- Anders Munch